Importing HTML Content

Posted by Community Admin on 04-Aug-2018 16:03

Importing HTML Content

All Replies

Posted by Community Admin on 13-Aug-2013 00:00
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();
Posted by Community Admin on 16-Aug-2013 00:00
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);

Regards,
Patrick Dunn
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
This thread is closed