In today's guide, I'm going to provide all the code you need to manually import comments into Disqus. If you were using Wordpress and you're converting your website into.NET or Umbraco then the easiest way to do this is to import your comments within Wordpress itself before you move your website over. Sometimes this isn't possible and you need to manually import your Wordpress comments into Disqus. In case you are wondering why you need to worry about Umbraco, when you import comments into Disqus, you can add a unique ID and Url. In your new website, the only way you can get this is using the Umbraco API. So without further ado, let's crack on.
GettingYour Comments Out Of Wordpress
This post assumes that you have exported your comments out of Wordpress using the Wordpress plug-in 'Export comments' and that you have all your comments within a CSV file locate on your computer. As we're using C# we'll use an MVC controller and view to read in the CSV file, add data into a view model and then iterate through that view model to create an XML file that writes that data in the WXR format that Disqus requires to import it.
So in terms of code, first-up is the view model. The view model itself is pretty straightforward.
Next, you use the controller code. This is where the logic happens that reads the CSV and converts it into our view models and returns it back to our view.
I'm hoping the code above is pretty simple to understand. One thing to note is that I'm using the VisualBasic TextFieldParser to do the CSV conversion. So, you will need to add a reference to Visual Basic! I'm also assuming that when you imported your blog posts from Wordpress to Umbraco, you also stored the Wordpress Id. If you didn't then that will make things a lot more complicated. If you find yourself in this situation, I suggest you try to re-import your Wordpress Id. To clarify, I have my Wordpress ID in my Umbraco document type within a property called '
After we have our comments in the format we need, it time to create the XML we need to import into Disqus. This is done in a razor view. My view is called 'disqus.cshtml'
The razor code above is also pretty simple. I went to the Disqus page and copied the XML format, listed by Disqus. I then iterate through all of my comments building up the page and inserting the relevant bits of data within the tags. Please note I'm using my Umbraco page ID and URL as the unique Disqus identifiers.
Importing Into Disqus
When you run your page you should now get a load of XML back with all your comments on it, in a format that Disqus will understand and allow. Be careful not to export the HTML, e.g. do a view page source, copy and paste your XML into a blank text file and save it. An example of my XML looked like this:
To import your file into Disqus you need to head to the import.disqus.com. From here you can upload your file and then check on the progress. Some useful things to note first, though. Make sure your file is a valid XML. Wordpress export can sometimes add funky things into your content, which you may need to manually correct invalid characters etc... You can check if your XML is valid using the free W3C validation service here. After your XML file is valid, your comments should import correctly, enjoy!