Working with pages programmatically

Posted by Community Admin on 04-Aug-2018 10:25

Working with pages programmatically

All Replies

Posted by Community Admin on 28-Aug-2012 00:00

Hi all,

I want to work with pages programmatically, if i want to add this code for example, where shoud i insert it?:

// create a new instance of CmsManager with default provider
Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
// create a new page with specified title
Telerik.Cms.ICmsPage newPage = cmsManager.CreatePage("About us");
// optionally, we can modify the properties of new page at this
// place, before actually saving the page
// created page finally needs to be saved with cmsManager
cmsManager.SavePage(newPage);

Posted by Community Admin on 28-Aug-2012 00:00

Please i am new with Sitefinity, i need to know, if i am editiing my sitefinity project in Visual Studio, which files should i edit or create to execute the previous code.. Thanks in advance.

Posted by Community Admin on 28-Aug-2012 00:00

Hi, I think we spoke via email but I'll post our discussion here too in case anyone else has the same question.

The code you’ve posted below is for Sitefinity 3.7, and is not compatible with the latest release. If you're using SF 4 or higher, you’ll want to use the new API.

 Sample code for creating and saving pages using code is available in the documentation: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/pages/creating-pages

 You can either use the standard PageManager API or the FluentAPI, both methods are explained and have sample code in the page linked above.

You could put execute this on a blank webforms page (create a test.aspx page and put it in the code behind) and run that page to execute it. You can also place it in a user control (ascx file) as a widget and drop it on a page to run it.

 Alternatively you could wrap it in a module, but this is more advanced and probably only necessary if you need something reusable. For more on module creation take a look at the testimonials intra site module example: http://www.sitefinity.com/documentation/documentationarticles/developers-guide/how-to/how-to-create-a-testimonials-intra-site-module

Hope this is helpful!

Posted by Community Admin on 30-May-2013 00:00

Hello,

If Mr. Morales is still around Sitefinity, how would you go about using this, or similar, code in order to upgrade your Custom 404 pages for Sitefinity 3.7 to the latest version of Sitefinity?
Ideally, we'd like to search a certain search index for pages that may interest the visitor.
Thanks.

Posted by Community Admin on 04-Jun-2013 00:00

Hello,

If you have created these pages inside Sitefinity 3.7 they will be migrated during the migration process. If the pages are created by code you need to recreate them using our Sitefinity documentation for pages.

Regards,
Stefani Tacheva
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