• Republishing Pages in Sitefinity 4.X

    by Venkata Koppaka | Jun 20, 2011

    If you would like to Republish pages in Sitefinity 4.X for any reason this post will help you write a custom page to do this task.

    Up until 4.1 this Republish page is a very important page to have as when you make changes to the template, the content pages did not get the latest changes from the template. You had to open up each and every content page and then hit Publish on that page. This is a cumbersome task especially if you have a lot of content pages.

    To ease up this procedure here is a quick asp.net page to Republish all pages(and clear the cache) -

    Create a page called RepublishPages.aspx on the root of the Sitefinity website. In the code behind of that page copy & paste the following code -

     

    1 using System; 
    2 using System.Linq; 
    3 using Telerik.Sitefinity; 
    4 using Telerik.Sitefinity.GenericContent.Model; 
    5 using Telerik.Sitefinity.Modules.Pages; 
    6 using Telerik.Sitefinity.Pages.Model; 
    7  
    8 namespace SitefinityWebApp 
    9
    10     public partial class RePublishPages : System.Web.UI.Page 
    11     { 
    12         protected void Page_Load(object sender, EventArgs e) 
    13         { 
    14             var pageNodes = App.WorkWith() 
    15                                          .Pages() 
    16                                          .LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend) 
    17                                          .Get() 
    18                                          .Where(pN => pN.Page.Status == ContentLifecycleStatus.Live) 
    19                                          .ToList(); 
    20             foreach (PageNode p in pageNodes) 
    21             { 
    22                 var myId = p.Page.Id; 
    23                 var manager = PageManager.GetManager(); 
    24                 var myDraft = manager.EditPage(myId, true);                 
    25                 manager.PublishPageDraft(myDraft, true); 
    26                 manager.SaveChanges(); 
    27             } 
    28         } 
    29     } 
    30

    And whenever you want to Republish pages just browse to this page and all the pages would be published with the latest changes.

     NOTE: Majority of the code is from this discussion - Not answered Adding content to template does not show on pages but changed a little according to my comment here .

    If you would like to download the Republish Page on the whole (aspx and codebehind)  Click Here

    Hope this helps

    Cheers

    Venkata


    Go comment!
  • Telerik MVC Music Store : MVC Music Store with Telerik OpenAccess ORM

    by Venkata Koppaka | Jun 14, 2011
    I would like to introduce you all to Telerik MVC Music Store. The sample is completely based off MVC Music Store, with Telerik OpenAccess ORM as database accessing mechanism.

    I would love if you download and give the project a try.

    Cheers 
    Venkata

    Go comment!
  • Telerik Open Access Orm : Include Equivalent - FetchStrategy

    by Venkata Koppaka | Jun 13, 2011

    ADO.NET Entity Framework 4.0 has an friendly method for loading related objects in a explicit way by using "Include"

    Below is an example from MVC Music Store.

    1 public ActionResult Browse(string genre) 
    2         { 
    3             // Retrieve Genre and its Associated Albums from database 
    4             var genreModel = storeDB.Genres.Include("Albums") 
    5                 .Single(g => g.Name == genre); 
    6  
    7             return View(genreModel); 
    8         } 

    In this method, Generes and Albums are related so EF provides an easy way to get both in a single call.

    But the main topic of this post is how to achieve this behavior if you are using Telerik OpenAccess ORM.

    See the code below -

    1         public ActionResult Browse(string genre) 
    2         { 
    3             // Retrieve Genre and its Associated Albums from database 
    4             FetchStrategy fetchStrategy = new FetchStrategy(); 
    5             fetchStrategy.LoadWith<Genre>(g => g.Albums); 
    6             storeDB.FetchStrategy = fetchStrategy; 
    7  
    8             Genre genreModel = storeDB.Genres.FirstOrDefault(g => g.Name == genre); 
    9  
    10             return View(genreModel); 
    11         } 

    You will need a "FetchStargegy" and Load Genre with Albums while getting the results.

    Hope this helps.

    Cheers

    Venkata


    Go comment!