Migrating Existing BlogEngine.Net Comments to Disqus

If you have been moderating a blog or writing your own, you must have experienced a lot of spammers invading your blog with comments. To solve it you might have disabled comments after a particular day, installed some extensions (plugins) to help you moderate your comments or even out-sourced you commenting system. Well, in my case I had decided to out-source it and choose Disqus as my commenting system. I was pretty lucky that I choose Disqus commenting system as BlogEngine.Net now officially allows to choose between either its own commenting system or Disqus commenting system, making it more easier for me to upgrade to newer versions as it wouldn’t require me to hack the BlogEngine.Net source code to inject some Disqus related codes.

One of the down side was that my blog already had some comments posted using the BlogEngine.Net. I didn’t want my old comments to be hidden (lost) and yet I wanted to choose some commenting system that would help me manage comments more easily. I decided to go with Disqus Comments after researching with its competitors.

I landed up disabling the BlogEngine.Net add new comments but still putting the old comments. Any new comments would had to be entered using the newly installed Disqus Comments as show below.

This was a temporary hack to use Disqus as the core commenting system. Later on with version 1.6.0.5 of BlogEngine.Net they officially supported Disqus Commenting system and would allow us to choose between the BlogEngine’s one or Disqus. Then I thought of migrating all my comments to Disqus as this would help me upgrade my blog more easily.

To solve this, I started searching for options to migrate existing comments to Disqus. They had official support for importing Intense Debate comments. I then created an extension for exporting BlogEngine.Net’s comments to Intense Debate comments xml format. But it was taking too long to import and finally gave me errors after importing. Tried it many times but was having no success. Finally I landed up writing a C# API to communicate with Disqus. The source code is open sourced and can be downloaded here (I’m using git version control system. please checkout to dev branch to see the codes). I decided to name it Disqus#.

Enough of the history. Lets start migrating.

First of you will need to download the BlogEngine.Net extension which allows you to export your blog engine.net comments at the end of the post. (Note: nested comments are not supported. This extension was created in hurry and is based on only my requirements.)

There are two things you will need to upload to your website. The extension it self called CommentsExporter.cs to App_Code\Extensions folder and the web-GUI front-end for exporting comments to User controls\ExportComments.aspx.

You will then need to login as the Blog moderator (administrator) and go to the extensions tab of the control panel.

Then select Edit link in the settings column of the CommentExporter. You will land up with the following page.

You can then click Export Comments button and choose Disqus Comments as the format. (Nested comments are not supported.) Map Authorized Users was basically created for exporting to Intense Debate (which I had chosen as my first export format, unfortunately it didn’t turn out well). This feature can still be used for Disqus Comments format. For example, in some of my comments I had written the author name as prabir or prabirshrestha. When I wanted to migrate I wanted to make them both as the same user – prabirshrestha. This was achieved by typing prabir:prabirshrestha; color(:) separates the key and value while semi-color(;) allows you to write more mappings. This is case sensitive too. You can write multiple values by entering prabir:prabirshrestha;Prabir:prabirshrestha; After you are done click the export button and save the exported comments. (The exported format is same as when you export comments from the Disqus website.)

Included with the download (below) there is a GUI frontend (Prabir.DisqusUploader) which looks similar as below.

Click browse and locate the file you just exported (saved) from the BlogEngine.Net website. You will need to then enter the User Api Key at the bottom left. If you don’t know your Disqus User Api Key, login to disqus and navigate to this link http://disqus.com/api/get_my_key/ Copy paste the User Api Key from the browser and click Get Websites button. Choose the appropriate website and click Upload to Disqus button. Once you are done with uploading a MessageBox is shows saying - "Your comments have been uploaded to Disqus."

Here’s the sample of uploaded Disqus Comments.

Then I finally upgraded my BlogEngine.Net to the latest version which supports Disqus Comments. The old comments were also removed. Finally I landed up as ...

Note: There is a small issue when uploading the comments to Disqus, it tends to truncate the comments if you have a single or double quote in the comments (‘ “) or have a semi-colon in the comments (;). I had to manually edit the truncated comments. If you want to fix it you can also download the source code. (Now that I am done migrating, most probably I wouldn’t have to be touching the source code, but if any one wants to contribute it back I would be more than happy.) Please use it at your own risk.

DisqusUploaderWithBlogEngineExtensions.zip (778.56 kb)

DisqusUploader-Src.zip (4.02 mb)