26 August 2007

Converting From MSN Live Spaces to DasBlog

by mo

So recently I managed to pull my posts from an old Live spaces account to merge them into my current DasBlog. It wasn’t an easy process and I lost things like comments from my posts. MSN Live Spaces exposes an MetaWeblogAPI to pull down your posts. There are limitations though… like you can only pull that last 20 posts using the “getRecentPosts()” method. All calls are carried over Xml Rpc.

MSDN documentation can be found here…

In order to pull data from your account you have to enable email publishing and specify a email publishing password this will be used for the RPC calls. I had a lot of problems pulling the correct data from the API. I wanted to get all of my entries, but I couldn’t use the “getRecentPosts()” method because it only returned the last 20 posts. So I had to use the “getPost()” method in a loop and try to get each individual post one at a time.

However, to get the post you have to use the post Id, so i started a loop from 0 to 300 to start grabbing Id’s. I found that each one of my posts had a similar prefix to the ID. They all started with “E2CAA5FD0245D158!” then had a number appended to it. Except the number didn’t increment by one, and I couldn’t find that pattern. So I started a loop from 0 to 2000 and appended the current counter index to the unique id.

Another issue I had was that the post date was not correct, every single post returned some strange date time that did not match the post data at all. To get around this I sent a web request for the actual html page and parsed out the date. This definitely was a hack for a solution…

The guts of the console app looks like this:

  MsnSpacesMetaWeblog mw = new MsnSpacesMetaWeblog( );
  SpaceSettings settings = new SpaceSettings( );

  mw.Credentials = new NetworkCredential( settings.Username, settings.Password );

  DasBlogWriter dasBlogWriter = new DasBlogWriter( settings.DefaultCategory );
  SpaceHtmlParser parser = new SpaceHtmlParser( settings.BlogUrl );
  for ( int i = 0; i < settings.UpperLimit; i++ ) {
      string entryId = settings.EntryIdPrefix + i;
      try {
          Post post = mw.getPost( entryId, settings.Username, settings.Password );
          post.dateCreated = parser.GetEntryDate( entryId );
          dasBlogWriter.Write( new SpacesEntry( post ) );
          Console.WriteLine( "Success: Entry Id " + entryId );
      catch {
          Console.WriteLine( "Failed to retrieve post with ID: " + entryId );
  Console.ReadLine( );

I told you it wasn’t pretty… Please feel free to the source and modify it as you need too… You will have to change the settings in the app.config file to match your settings.

Good Luck!

SpacesToDasBlog.zip (700.77 KB)