More in this section

Forums / Developing with Sitefinity / Importing HTML Content

Importing HTML Content

2 posts, 0 answered
  1. Don
    Don avatar
    9 posts
    27 Sep 2012
    13 Aug 2013
    Link to this post
    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

       // Save the changes
  2. Patrick Dunn
    Patrick Dunn avatar
    237 posts
    03 Nov 2014
    16 Aug 2013
    Link to this post
    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);

    Patrick Dunn
    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
2 posts, 0 answered