Creating new smartform data using Ektron ContentTypes

邮差的信 提交于 2019-12-11 10:57:11

问题


Ektron 8.0.1 SP1

I am using SmartForms and Content Types to read (and hopefully write) data. I can read data but now I am attempting to write a new record similar to the following.

ContentTypeManager<member> contentTypeManager = new ContentTypeManager<member>();
ContentType<member> newmem = new ContentType<member>();

newmem.SmartForm.details.field1 = "Chuck"; // This line throws 'Object reference not set to an instance of an object.' error
newmem.SmartForm.details.field2 = "Norris";
contentTypeManager.Update(newmem);

I get the error "Object reference not set to an instance of an object." for that first assignment line. What am I missing?

I am having trouble finding good documentation on ContentTypes for 8.0.1 now that the Ektron website has been redesigned.

Thx.


回答1:


Thanks for clarifying, to ADD content to a folder that has a smartform assigned to it, the basic code block should get you started: (Note: the Html attribute of the content is simply the xml matched to the schema you created)

Ektron.Cms.Framework.Content.ContentManager cmanager = new Cms.Framework.Content.ContentManager();
Ektron.Cms.ContentData cdata = new ContentData();
cdata.FolderId = 0;
cdata.XmlConfiguration.Id = 0; //SMARTFORM ID HERE
cdata.Html = "<root><field1>field1 value</field1><field2>field2 value</field2></root>";
cmanager.Add(cdata);



回答2:


You could update ContentTypes.cs to include an Add method. Just copy the Update method and change contentManager.Update to contentManager.Add.

    public void Add(ContentType<T> contentType)
    {
        Initialize();
        contentType.Content.Html = Ektron.Cms.EkXml.Serialize(typeof(T), contentType.SmartForm);
        contentManager.Add(contentType.Content);
    }

Unfortunately, contentManager.Add returns void. Ideally it should return the new content ID.



来源:https://stackoverflow.com/questions/14592620/creating-new-smartform-data-using-ektron-contenttypes

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