1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Create Blog Using Code

Create Blog Using Code

6 posts, 0 answered
  1. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    02 Nov 2010
    Link to this post
    I need to load a blog control and configure it using code
    There must be a way to do this but it doesn't seem straight forward to me. I have successfully created my custom controls and added them to a page using code. How would one go about adding controls already part of the system and configuring the properties on the controls such as the blog control? It would be nice if I could automate a basic blog setup so that I could single click blog setup for beginners
     
    I intend to do this for all the module components inSitefinity
    This one solution should get me the rest of the way.
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    02 Nov 2010
    Link to this post
    Hello jaime,

    Thank you for using our services.

    Bellow is a sample code snippet which you can use to add a posts view control on the page:
    PageManager pageManager = PageManager.GetManager();
    //get page to which we are going to add hte control
    var page = pageManager.GetPageDataList().Where(t => t.Title == "Home").SingleOrDefault();
    //get a placeholders lists, we are going to use this so that we define the placeholder to which we are going to add the control
    List<PageControl> controls = page.Controls.Where(c=> c.IsLayoutControl == true).Cast<PageControl>().ToList();
    PageDraft editPage = pageManager.EditPage(page.Id, false);
    //instantiate a new BlogPostsView control
    BlogPostView postsView = new BlogPostView();
    //create a page control from it and add it to the page
    var pageControl = pageManager.CreateControl<PageDraftControl>(postsView,controls[0].PlaceHolder);
    editPage.Controls.Add(pageControl);
    pageManager.PublishPageDraft(editPage,true);
    pageManager.SaveChanges();

    In the Beta 2 version due to some protection levels you cannot set the posts view properties through code, unless you are inheriting from this control. This has been fixed for the RC and when you get the RC version next week you should be able to programmatically set properties bellow you create the page control:
    BlogPostView p = new BlogPostView();
    p.MasterViewDefinition.ItemsPerPage = 5;
    p.MasterViewDefinition.TemplatePath = "PathToExternalTemplate";


    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jaime Weise
    Jaime Weise avatar
    120 posts
    Registered:
    02 Nov 2008
    03 Nov 2010
    Link to this post
    There are no controls in the collection
    In the following line of code there are no controls in the collection.
    List<PageControl> controls = page.Controls.Where(c => c.IsLayoutControl == true).Cast<PageControl>().ToList();
    I think we are missing something here. 


  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Nov 2010
    Link to this post
    Hi jaime,

    The error is saying that the page does not contain layout controls. I have prepared this sample to work for a page which does not use a master page for template, but rather a template built from the UI, containing layout controls. If your page's template derives from a master page you can use the content place holder's IDs when you create the page control.

    All the best,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Roopesh
    Roopesh avatar
    39 posts
    Registered:
    29 Oct 2010
    12 Nov 2010
    Link to this post
    Hello,
     
    I developed a single item display control for blog.  How can i replace my control with SF's default single item display control?
    Thank You
    Roops
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    12 Nov 2010
    Link to this post
    Hello Roopesh,

    You can register your control through the web.config <toolboxControls> section and then use it on your page.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
6 posts, 0 answered