Move Blog

Posted by Community Admin on 03-Aug-2018 19:58

Move Blog

All Replies

Posted by Community Admin on 06-May-2011 00:00

Hey guys - i am trying to move blogs posts from one blog to the other - i don't seem to see the option for that 

how can this be done - i cannot go and rewrite all the blog posts in a different blog.....

Thanks!

Posted by Community Admin on 06-May-2011 00:00

you can do this with the BlogsManager API. Create a new page like CopyBlogPosts.aspx and put something like this in the code behind:

protected void Page_Load(object sender, EventArgs e)
    // retrieve manager
    var blogMgr = BlogsManager.GetManager();
    // retreive blogs
    var oldBlog = blogMgr.GetBlogs().SingleOrDefault(b => b.Title == "Test Blog 1");
    var newBlog = blogMgr.GetBlogs().SingleOrDefault(b => b.Title == "Test Blog 2");
    // parse through old posts, only get published ones (avoids duplicates)
    foreach (var oldBlogPost in oldBlog.BlogPosts.Where(p => p.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live))
    
        // create new post
        var newBlogPost = blogMgr.CreateBlogPost();
        // copy properties
        newBlogPost.Parent = newBlog;
        newBlogPost.Title = oldBlogPost.Title;
        newBlogPost.UrlName = oldBlogPost.UrlName;
        // ...
        blogMgr.Publish(newBlogPost);
        // add post to new blog
        blogMgr.SaveChanges();
    


Build the website and visit that page. It should execute, copying all the posts from one blog to the other. Of course this example omits checking permissions and is very basic but should give you an idea of how you can implement this.

Of course I highly recommend you backup as always to be safe, and only run this locally then push the finished site out live.

I hope this was helpful!

Posted by Community Admin on 07-May-2011 00:00

info was useful

This thread is closed