I wanted to move away from Blogger for quite some time now, but I always feared the difficulties in exporting my Blogger posts (and comments, don’t forget about the comments!) and importing them into a dasBlog installation. Well, my fear was totally gratuitous, it’s actually pretty easy. Here’s how I did it:
- First, go to your Blogger settings, set the number of posts to display to 999 and the timestamp format to MM/DD/YYYY HH:MM:SS. Save these settings but don’t publish.
- Next, edit your main template and change it to this:
<?xml encoding="utf-8" ?>
<entries>
<Blogger>
<entry>
<title><![CDATA[<$BlogItemTitle$>]]></title>
<body><![CDATA[<$BlogItemBody$>]]></body>
<date><![CDATA[<$BlogItemDateTime$>]]></date>
<BlogItemComments>
<comment>
<commentauthor><![CDATA[<$BlogCommentAuthor$>]]></commentauthor>
<commenttext><![CDATA[<$BlogCommentBody$>]]></commenttext>
</comment>
</BlogItemComments>
</entry>
</Blogger>
</entries> - Now, don’t publish or save, only press Preview. Get the HTML source of the preview page, and copy everything between (and including) <?xml …> and </entries>, and save it to a new xml file. I called my file archive.xml. Now we’ve all your posts and comments stored in a nice XML file. Close Blogger, we won’t need it anymore.
- Behold, here comes the tough part (but it’s still pretty easy). Create a new C# console application in Visual Studio (it will work without Visual Studio of course, but I’m really not a fan of using the compiler with the command line), and paste this code (sorry for the missing comments, but I think it’s pretty straight forward):
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Globalization;
using newtelligence.DasBlog.Runtime;namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {XmlDocument doc = new XmlDocument();
doc.Load(@"d:archive.xml"); //change this pathIBlogDataService dasBlog = BlogDataServiceFactory.GetService(@"c:content", null); //change this path
foreach (XmlElement elem in doc["entries"].GetElementsByTagName("entry")) {
Console.WriteLine(elem["date"].InnerText);
CultureInfo c = new CultureInfo("en-us");
DateTime date = DateTime.Parse(elem["date"].InnerText, c);Entry entry = new Entry();
entry.Author = "Saxx";
entry.Content = elem["body"].InnerText;
entry.Description = "";
entry.Title = elem["title"].InnerText;
entry.CreatedLocalTime = date;
entry.CreatedUtc = date.ToUniversalTime();
entry.ModifiedLocalTime = date;
entry.ModifiedUtc = date.ToUniversalTime();
entry.EntryId = Guid.NewGuid().ToString();
dasBlog.SaveEntry(entry);foreach (XmlElement e in elem.GetElementsByTagName("comment")) {
Comment comment = new Comment();string author = e["commentauthor"].InnerText;
if (author.Contains(">")) { //removes the links around the comment authors names
author = author.Substring(author.IndexOf(">") + 1);
author = author.Substring(0, author.IndexOf("<"));
}
Console.WriteLine(author);comment.EntryId = Guid.NewGuid().ToString();
comment.TargetEntryId = entry.EntryId;
comment.Content = e["commenttext"].InnerText;
comment.Author = author;
comment.CreatedLocalTime = date;
comment.CreatedUtc = date.ToUniversalTime();
comment.ModifiedLocalTime = date;
comment.ModifiedUtc = date.ToUniversalTime();dasBlog.AddComment(comment);
}
}
}
}
}
- Next, change the two paths in this code according to your system. I had my archive.xml stored on drive D: and I created a directory content on drive C:. This directory is where the dasBlog posts will go – you’ll have to create it manually before running the code.
- One last step. Add a reference to the file newtelligence.DasBlog.Runtime.dll, that is found in the /bin directory of dasBlog, to your console application. In this assembly is all the intelligence we need to (re)create the posts for dasBlog.
- That’s it, run the application. Depending on the number of posts and comments it can take a while, but when it’s done you’ll have a lot of XML files in your target folder (remember, mine was c:content). Now copy these files to the /content directory of dasBlog. That’s it. Thanks go to Rick Hallihan who gave me some ideas.
da fehlt ein "<".Wo, das musst du selber rausfinden 😉
Wo denn? ich finds nicht 🙁