Create Blog Using Code

Posted by Community Admin on 03-Aug-2018 08:59

Create Blog Using Code

All Replies

Posted by Community Admin on 02-Nov-2010 00:00

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.

Posted by Community Admin on 02-Nov-2010 00:00

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

Posted by Community Admin on 03-Nov-2010 00:00

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. 


Posted by Community Admin on 03-Nov-2010 00:00

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

Posted by Community Admin on 12-Nov-2010 00:00

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

Posted by Community Admin on 12-Nov-2010 00:00

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

This thread is closed