Scott Hanselman

Migrating Content from Random Blogs to DasBlog

September 23, 2005 Comment on this post [9] Posted in ASP.NET | DasBlog | XML
Sponsored By

This guy Ernie emailed me saying that he had some random, possibly home-grown, blog with content in Access that he wanted to migrate to his new DasBlog. I don't ordinarily do this (and don't plan to ever again) but it's so easy to move content into DasBlog that I decided to take this opportunity to write an example I could point other folks to.

Note: this is just an example that converted Ernie's blog. It's not something that will work unchanged for you, so don't ask. :) Ernie had a "news" table and a "comments" table. Blog posts were in news and used "blogid" as a unique id.

Additional note: Often you can use the same unique ids in DasBlog. You don't need you use a GUID for the DasBlog EntryId. In this case, Ernie's BlogID was just an int and it was unique enough. He could implement redirects if someone visited /myoldblog.asp?id=4 to /mynewdasblog/permalink.aspx?guid=4 and all his old content would get reindexed by Google and none of the old links would be invalid.

Just make a Console application in C# or VB.NET and add a reference to newtelligence.DasBlog.Runtime. I used a DataReader and just hard-coded the indexes of each column. It's not like this will ever be run again. It takes a little while to run because the DasBlog engine expects to run in the context of ASP.NET so it isn't able to use the ASP.NET Cache. The performance degrades O^n when run locally as your content folder grows. If that becomes a problem, run your converter in the context of IIS/ASP.NET and you'll get the high speed access.

In this example, the DasBlog dayentry.xml and dayfeedback.xml files will be left in the directory that the application was run in. I also converted newlines to <br> and when a blog post didn't include a title, I used the first 20 characters of the post as the title.

This took about 15 mins at lunch, so you really can transfer all your existing blog's data to DasBlog quickly, usually using just the Entry class and the Comment class. Note how they relate to each other using the EntryId as the key.

static void Main(string[] args)
    IBlogDataService dataService = 
    string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;
Data Source=ernie.mdb;Mode=Share Deny None";
    using(OleDbConnection conn = new OleDbConnection(connStr))
        using(OleDbCommand newsCmd = new OleDbCommand("select * from News",conn))
            using (OleDbDataReader reader = newsCmd.ExecuteReader())
                    int blogId = reader.GetInt32(0);
                    DateTime date = reader.GetDateTime(1);
                    DateTime time = reader.GetDateTime(3);
                    DateTime correctDate = 
new DateTime(date.Year,date.Month,date.Day,time.Hour,time.Minute,time.Second);
                    string blogText = reader.GetString(2);
                    string blogTitle = reader.IsDBNull(4) ? String.Empty : reader.GetString(4);
                    Entry entry = new Entry();
                    entry.CreatedLocalTime = correctDate;
                    entry.ModifiedLocalTime = correctDate;
                    entry.Title = 
(blogTitle.Length > 0 ? blogTitle :
                    entry.Content = blogText.Replace("\r\n","<br>");
                    entry.EntryId = blogId.ToString();
                    entry.Categories = "main;old site";
                    entry.Author = "Ernie";
        using(OleDbCommand newsCmd = new OleDbCommand("select * from comments",conn))
            using (OleDbDataReader reader = newsCmd.ExecuteReader())
                    int blogId = reader.GetInt32(1);
                    DateTime date = reader.GetDateTime(4);
                    string commentText = reader.GetString(2);
                    string commentName = reader.GetString(3);
                    Comment comment = new Comment();
                    comment.CreatedLocalTime = date;
                    comment.ModifiedLocalTime = date;
                    comment.TargetEntryId = blogId.ToString();
                    comment.Author = commentName;
                    comment.Content = commentText;

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
September 26, 2005 17:03
How to move from blogger to dasblog ?
September 27, 2005 4:03
As much as I despise the language, this might be a perfect example of an instance where perl would be appropriate. Some cheesy little script that will never, ever be run again.

Of course, those things have a way of sticking around, so python still seems like a better choice. C# is just overkill.
September 27, 2005 7:43
Hm...I hear what you're saying kind of Terry, but "overkill?" Um, how do you figure? That's like 25 lines...not sure how that's heavy or overkill.
September 27, 2005 7:46
Andrei, to export, do this: to your blogger account, then write a small program to transform this format into the DasBlog format. If you do this, send me the resulting export file and I'll take a look.
September 28, 2005 8:01
Andrei: I followed the same pattern above to make a GUI for porting Blogger content over to das blog. You can find it on my blog.
November 17, 2005 7:16
flippin' awesome. This is the clincher. I took about 20 minutes modifying the code and voila, all my content from my circa 2002 ASP/Access CMS gets imported into das blog. I am in the process of porting my site and will have it running on DasBlog by next Monday.

Saweet, thanks Scott.
December 22, 2005 4:23
I did the conversion, yet when I put the resulting xml files in the /content directory, they aren't displayed. What else do I need to do?

December 22, 2005 4:31
Ahh, restarting IIS appears to have done the trick
January 02, 2006 18:46
I modified your code to move my blog over to dasblog (it was previously .Text and the alternatives seemed to be overkill and not as functional). I put the resulting files in my /content directory and asked my sharedhosting admin to reset IIS, the old posts are still not visible. Any ideas?

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.