public
Created

Recompile (re-evaluate) the URL associated with all Sitefinity blog posts

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
using System;
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Modules.Blogs;
using Telerik.Sitefinity.Blogs.Model;
 
namespace SitefinityWebApp.Extensions
{
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var manager = BlogsManager.GetManager();
foreach (var post in App.WorkWith().BlogPosts().Get().ToList())
{
Response.Write(post.Title + "<br />");
var editPost = manager.GetBlogPost(post.Id);
manager.RecompileItemUrls<BlogPost>(editPost);
manager.Lifecycle.Publish(manager.Lifecycle.GetMaster(editPost));
manager.SaveChanges();
}
}
}
}

I changed the UrlFormat property associated with my Sitefinity blog posts to change the URL generated for each post. Once this property is updated, the old blog posts continue to use the old URL until manually re-saved. I didn't want to manually click through and re-save each blog post, so I used the code above to automatically recompile the URL associated with each blog post.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.