Reputation: 2682
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);
Upvotes: 2
Views: 838
Reputation: 2682
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);
Upvotes: 2