Skip to content

Instantly share code, notes, and snippets.

@gabesumner
Created September 5, 2011 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabesumner/1195950 to your computer and use it in GitHub Desktop.
Save gabesumner/1195950 to your computer and use it in GitHub Desktop.
Recompile (re-evaluate) the URL associated with all Sitefinity blog posts
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();
}
}
}
}
@gabesumner
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment