以编程方式创建smartform ektron

时间:2014-06-18 19:15:41

标签: c# ektron

我创建了smartform并使用bat文件生成了相关的类(使用xsd生成c#类)。然后我将创建的smartform分配给特定文件夹,然后使用CMS工作区创建了样本smartforms。

有没有办法从代码后面创建智能表单?我尝试了如下,但它没有按预期工作:

    ContentType<root> cData = new ContentType<root>();
    cData.SmartForm.EventName = "Conference Event1";
    cData.SmartForm.EventDescription = "Test Description";
    cData.SmartForm.EventDate = DateTime.Now.AddMonths(2).ToString("yyyy-MM-dd");


    ContentTypeManager<root> contentTypeManager = new ContentTypeManager<root>();
    contentTypeManager.Add(cData);

1 个答案:

答案 0 :(得分:2)

我找到了解决方案。您可以使用ContentManager实现它。

    ContentManager contentManager = new ContentManager(ApiAccessMode.Admin);
    Ektron.Cms.ContentData contentData = new Ektron.Cms.ContentData();
    contentData.Title = "title 011";
    contentData.Html = "<root><EventName>Change1...</EventName>" +
                     "<EventDescription>Description Test</EventDescription>" +
                     "<EventDate>2014-10-30</EventDate>" +
                     "</root>";
    contentData.ContType = 1;
    contentData.Comment = "Automatically generated from a script.";
    contentData.FolderId = 86; //folder id to save you smart data
    contentData.IsPublished = true;
    contentData.IsSearchable = true;
    contentData.LanguageId = 1033;
    contentData.XmlInheritedFrom = 86; //folder id to save you smart data
    Ektron.Cms.XmlConfigData xcd = new Ektron.Cms.XmlConfigData();
    xcd.Id = 7; //SmartForm ID
    contentData.XmlConfiguration = xcd;
    contentManager.Add(contentData);