2

I have created the smartform and generated the relevant class using a bat file (using xsd to generate c# class). Then I assigned that created smartform to a particular folder and I created the sample smartforms using the CMS work area.

Is there a way to create a smartform from code behind? I have tried as follows, but it didn't work as expected:

    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);
Divi
  • 7,621
  • 13
  • 47
  • 63
Shanaka Rathnayaka
  • 2,462
  • 1
  • 23
  • 23

1 Answers1

2

I have found the solution. You can achieve it using 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);
Divi
  • 7,621
  • 13
  • 47
  • 63
Shanaka Rathnayaka
  • 2,462
  • 1
  • 23
  • 23
  • I already have a smart form that I would like to programmatically update. Will this do it as well? – Si8 Oct 07 '15 at 19:23
  • Also, how can I check to ensure another content with the same title doesn't exist before creating a new content? Thanks. – Si8 Oct 20 '15 at 19:36