Importing HTML Content
I can't seem to find a specific code example for what I need. I am writing code to import HTML documents into Sitefinity - it works except for the last piece of trying to use the SDK to add a content block widget to the page and fill it with the HTML content. My code is below - can someone point me in the right direction? This code doesn't add the content block to the page - much less the HTML content itself. Note - I get the page successfully. Thanks!
// Get the page
PageManager manager = PageManager.GetManager();
var page = manager.GetPageNodes().Where(p => p.Id == file.Id).SingleOrDefault();
// Create content block page control
ContentBlock aspxContent = new ContentBlock();
aspxContent.Html = file.AspxContent;
aspxContent.Visible = true;
aspxContent.ID = "ASPX" + file.Id.ToString();
PageControl aspxContentControl = manager.CreateControl<PageControl>(aspxContent, "AspxContent");
aspxContentControl.Caption = "Page Content";
// Add the control to the page
page.Page.Controls.Add(aspxContentControl);
// Save the changes
manager.SaveChanges();
Hello Don,
Thank you for using Sitefinity.
You're not specifying a content placeholder to add the control to. Without this being specified the system has no idea where to put your control.
You need something like this:
dynamic usercontrol = BuildManager.CreateInstanceFromVirtualPath("~/mycontrol.ascx", typeof(UserControl));
usercontrol.Message = "Hello World"; // Some public property on this user control.
PageDraftControl pageDraftControl = pageManager.CreateControl<
PageDraftControl
>();
pageDraftControl.ObjectType = "~/mycontrol.ascx";
pageDraftControl.PlaceHolder = "ContentPlaceHolder1";
pageManager.ReadProperties(usercontrol, pageDraftControl);
draftPage.Controls.Add(pageDraftControl);