How I moved my blog posts to Community Server 2.0

I see that you’ve found my new technical blog. Welcome. Just so you know I’m using Community Server 2.0 as the software for this blog. I have loaded all of the posts in the Tech category on my personal blog at www.jorriss.com on this site. To do this I was able hook into the Community Server web service, loop through my technical blog posts (stored in .Text) and load each post. I wasn’t worried about the comments or referrals since I wasn’t going to remove the original posts from jorriss.com. This way, I get a fresh blog with all of my original tech posts. And yes, a new design is coming. Here is a code listing of how I ported the data. It’s simple, It’s dirty, It works.

public static void PostBlogDataWS() {

  // Get Old Blog Data
  SqlConnection connOldBlog = new
SqlConnection(); 
  // Replace servername, database, userid, password with the .Text DB values
  connOldBlog.ConnectionString=”Data Source=servername;initial catalog=databasename;user id=userid;password=password;”;
  connOldBlog.Open();
  SqlDataReader blogData;
  SqlCommand cmd =
new
SqlCommand();
  cmd.Connection = connOldBlog;
  cmd.CommandText = “select b.title, dateadded, text from blog_content b join blog_links l on b.id =  l.postid and categoryid = 2″;
  blogData = cmd.ExecuteReader();

  // Loop through blog posts and load them into CS via the WS
  while(blogData.Read()) {
    net.ws.BlogPost post =
new
net.jorriss.BlogPost();
    net.ws.BlogService bservice =
new
net.jorriss.BlogService();
    net.ws.ServiceCredentials bcred =
new
net.ws.ServiceCredentials();

    bcred.Username = “username“; // use your CS username
    bcred.Password = “password“; // use your CS password
    bcred.SectionName = “blogappkey“; // use your CS blog appkey

    post.Body = blogData[2].ToString();
    post.Date = Convert.ToDateTime(blogData[1].ToString());
    post.FormattedBody = blogData[2].ToString();
    post.IsPublished =
true

    post.Title = blogData[0].ToString();
    post.Syndicate =
true
;
    post.EnableTrackbacks =
true
;
    post.EnableComments =
true
;
    post.EnableAllOwnerNotification =
true
;
    post.EnableRatings =
true
;
    post.EnableCrossPosting =
true
;
    post.SydicateRoot =
true
;
    post.FeedbackNotificationType = net.ws.FeedbackNotificationType.AllFeedback;
    bservice.ServiceCredentialsValue =bcred;
    bservice.Create(post);
  }
  connOldBlog.Close();
}