I have a problem creating components using the coreservice. I create components with code on master level(tcm:76). The given source code of the master component is correct, but when viewing this component on another level like tcm:6,.. the links in the source code won't change. until I open the component and press the save button in tridion itself. I don't wan't to do this for all the components I create because this is a lot of work. (+- 1000 items.) Does anybody knows the answer for this?? Thanks in advance
protected ComponentData createImageComponent(Image image, string schemaId, string locationId, ICoreService client) {
try {
SchemaData schemaData = client.Read(schemaId, new ReadOptions()) as SchemaData;
string uuid = schemaData.NamespaceUri;
ComponentData component = (ComponentData)client.GetDefaultData(ItemType.Component, locationId);
component.Id = "tcm:0-0-0";
component.Title = image.imageTitle;
component.Schema = new LinkToSchemaData { IdRef = schemaId };
StringBuilder sb = new StringBuilder();
image.changeTo76();
sb.Append("<Content xmlns=\"").Append(uuid).Append("\"><ThumbSource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
sb.Append(image.thumbSource).Append("\" xlink:title=\"").Append(image.thumbTitle).Append("\"></ThumbSource><PhotoSource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\"");
sb.Append(image.imageSource).Append("\" xlink:title=\"").Append(image.imageTitle).Append("\"></PhotoSource></Content>");
component.Content = sb.ToString();
component.LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = locationId } };
ComponentData componentData = (ComponentData)client.Create(component, readOptions);
return componentData;
} catch (Exception e) {
txtConsole.ForeColor = Color.Red;
txtConsole.Text += "\n Exception createImageComponent \n StackTrace: \t" + e.StackTrace.ToString() + " Message: " + e.Message.ToString();
txtConsole.ForeColor = Color.Black;
return null;
}
}
This code will create a component on our 'Master' level. with 'tcm:76' which is correct.
<Content xmlns="uuid:e0bc7848-a25a-41b0-8f02-ac4e1d4250bb">
<ThumbSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-554-dist-file" xlink:title="120x85_17.jpg"></ThumbSource>
<PhotoSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-579-dist-file" xlink:title="685x555_17.jpg"></PhotoSource>
</Content>
When I open this component on another level with "tcm:6", I retrieve this source which is wrong: the href still gives back ecl:76 while it must return ecl:6!
<Content xmlns="uuid:e0bc7848-a25a-41b0-8f02-ac4e1d4250bb">
<ThumbSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-554-dist-file" xlink:title="120x85_17.jpg"></ThumbSource>
<PhotoSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:76-mm01-579-dist-file" xlink:title="685x555_17.jpg"></PhotoSource> </Content>
If I open this component on master level in tridion(no coding). I enter a whitespace in the description of the component en delete this back.(need to edit something to be able to save the component). Then I press the "save" button in tridion and look back to the source. it returns the correct source:
<Content xmlns="uuid:e0bc7848-a25a-41b0-8f02-ac4e1d4250bb">
<ThumbSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:6-mm01-554-dist-file" xlink:title="120x85_17.jpg"></ThumbSource>
<PhotoSource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ecl:6-mm01-579-dist-file" xlink:title="685x555_17.jpg"></PhotoSource>
</Content>