1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Move Blog

Move Blog

3 posts, 0 answered
  1. RebootLN
    RebootLN avatar
    25 posts
    Registered:
    21 Aug 2010
    06 May 2011
    Link to this post
    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!
  2. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    06 May 2011
    Link to this post
    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!
  3. poovi
    poovi avatar
    3 posts
    Registered:
    06 May 2011
    07 May 2011
    Link to this post
    info was useful
3 posts, 0 answered