Updating Components using the Core Service in SDL Tridion 2011

前端 未结 3 952
别跟我提以往
别跟我提以往 2020-12-17 06:58

I am updating a Component using Core Service in Tridion 2011.

The sample code is as follows,

string COMPONENT_URI = \"tcm:8-674\";
string SCHEMA_URI          


        
3条回答
  •  天命终不由人
    2020-12-17 07:23

    Sometimes, specially if you are synchronizing the content from a different repository that acts as the master, you can just reconstruct the component from scratch. In that case, here is a basic example of how to do that:

        public static void updateComponent()
        {
            string componentWdUrl = "/webdav/020%20Content/Building%20Blocks/Content/wstest/testComponent.xml";
            CoreServicesUtil coreServicesUtil = new CoreServicesUtil();
            coreServicesUtil.coreServiceClient.CheckOut(componentWdUrl, true, coreServicesUtil.readOptions);
            ComponentData componentData = coreServicesUtil.getComponentData(componentWdUrl);
            SchemaData schemaData = coreServicesUtil.getSchemaData(componentData.Schema.IdRef);
            componentData.Content = xmlUtil.GetNewXmlNode("Content", schemaData.NamespaceUri);
            componentData.Metadata = xmlUtil.GetNewXmlNode("Metadata", schemaData.NamespaceUri);
            componentData.AddSingleField("singlefield", "singlefield sample", schemaData.NamespaceUri);
            componentData = (ComponentData)coreServicesUtil.coreServiceClient.Save(componentData, coreServicesUtil.readOptions);
            coreServicesUtil.coreServiceClient.CheckIn(componentData.Id, coreServicesUtil.readOptions);
            coreServicesUtil.coreServiceClient.Close();
        }
    

    More description about methods used in this sample are explained in the article:

    Faulted State error while creating component with Core Service

提交回复
热议问题