How to set content to a component without loading XML in SDL Tridion using core services?

允我心安 提交于 2019-12-03 00:19:01

问题


How do I set content to a component without loading XML in SDL Tridion using core services?


回答1:


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



回答2:


This might help: http://blog.building-blocks.com/uploading-images-using-the-core-service-in-sdl-tridion-2011 http://blog.building-blocks.com/creating-custom-pages-using-the-core-service-in-sdl-tridion-2011



来源:https://stackoverflow.com/questions/10443439/how-to-set-content-to-a-component-without-loading-xml-in-sdl-tridion-using-core

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!