Tridion CoreService创建缺少元数据的组件

时间:2012-09-27 15:43:32

标签: metadata tridion

我得到异常= {“无法找到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专家

1 个答案:

答案 0 :(得分:12)

您的路径正确,但错误表示您尚未为要创建的组件提供元数据字段。

此行不正确:

Metadata = schemaData.Metadata

它应该就像你创建内容字段的那样:

Metadata = String.Format("<Metadata xmlns=\"{0}\">{1}</Metadata>",schemaData.NamespaceUri, "YOUR METADATA XML")