7

我得到异常 = {“无法找到 uuid:5708986b-390f-4728-b0c7-b49bd3d8f407:元数据。”}

schemaId = UpdatePubId(schemaId, containerId);
SchemaData schemaData = (SchemaData)client.Read(schemaId, null);
string xml = string.Format("<{0} xmlns=\"{1}\">{2}</{0}>", schemaData.RootElementName, schemaData.NamespaceUri, fields);

ComponentData componentData = new ComponentData
{
    Content = xml,
    ComponentType = ComponentType.Normal,
    Title = title,
    Schema = new LinkToSchemaData { IdRef = schemaId },
    LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = containerId } },
    Id = "tcm:0-0-0", 
    MetadataSchema = schemaData.MetadataSchema,
    Metadata = schemaData.Metadata
};

try
{
    componentData = client.Save(componentData, new ReadOptions()) as ComponentData;
    componentData = client.CheckIn(componentData.Id, new ReadOptions()) as ComponentData;
    message.Set("Component", title + ", successfully");
}
catch (Exception exception)
{
    message.Set("Component", exception.Message);
}

感谢 Tridion 专家

4

1 回答 1

13

您在正确的路径上,但错误表明您没有为您尝试创建的组件提供元数据字段。

此行不正确:

Metadata = schemaData.Metadata

它应该非常像您创建内容字段的那个:

Metadata = String.Format("<Metadata xmlns=\"{0}\">{1}</Metadata>",schemaData.NamespaceUri, "YOUR METADATA XML")
于 2012-09-27T16:27:35.417 回答