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
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