How do I set content to a component without loading XML in SDL Tridion using core services?
Asked
Active
Viewed 834 times
-1
-
1This question is very unclear. What kind of content are you trying to set etc? Given that all text based content (i.e. all components data except binaries) is stored in XML, why are you trying to avoid XML? Perhaps you can update the question. – Chris Summers May 04 '12 at 11:30
2 Answers
2
If you are looking to create a regular Component through the Core Service, you can avoid having to craft the XML yourself by using this helper class.
With this you can create a Component like this:
schemaFields = client.ReadSchemaFields("tcm:1-2-8", true, DEFAULT_READ_OPTIONS);
component = (ComponentData)client.GetDefaultData(ItemType.Component, "tcm:1-57-2");
fields = Fields.ForContentOf(schemaFields);
component.Title = "Name of component (created at "+ DateTime.Now + ")";
fields["Title"].Value = "Title of newly created component";
fields["Intro"].Value = "Intro of newly created component";
fields["Section"].AddValue("This is the first section");
fields["Section"].AddValue("This is the section section");
component.Content = fields.ToString();
component = (ComponentData)client.Create(component, DEFAULT_READ_OPTIONS);

Frank van Puffelen
- 565,676
- 79
- 828
- 807