Migrating data from ASP to WordPress

August 5th, 2009 | Tutorials

My personal site ArleyM.com has been an ASP site for about six years now, but the time has finally come to port over to WordPress and PHP. A lot of the heavy lifting was done over a year ago when I experimented with using Blogger as an RSS powering blog engine, but there was still some content fueled by a Microsoft Access Database.

In early 2004 I started a database of my Top5 high rotation songs of the week. This was a very simple database table with eight fields. It’s been very rewarding to see this progress kept, so naturally I want to bring it into the new site. On the former version of the site ASP calls the database, and repeats each row of data in a table. I could just copy and paste the HTML tables after they’ve been rendered, but where’s the fun in that? I’d prefer to have each table fall into my blog on the appropriate date for the last five years.

click to enlarge

click to enlarge

WordPress naturally doesn’t import .mdb files natively, so I knew there would be some wrestling with data! Under Tools > Import WordPress has several proprietary formats it can import, as well as the ubiquitous RSS feed. I decided to convert my database into RSS.

At first I thought it might be a simple matter of exporting the XML (which RSS is a form of), but this was going to require some ugly code work to fit the RSS 2.0 format. In the end, I modified the old recordset page to render the RSS for me!

The old recordset page would call to the database, then populate a table with the songs like so:

Old Table Render

This was done with code like:

<tr>
<td width=”13%”>one.</td>
<td width=”87%”><%=(t5.Fields.Item(“songone”).Value)%></td>
</tr>

So it’s just a simple matter of changing up the body content! Obviously I don’t want to do my site layout in Tables again, opting for CSS styling on a list.

As already stated, ASP gathers the records in a Repeat Region. RSS likes content repeated with the <item> tag. So in the end my new ASP record code looked like:


<item>
<title>Top5 Tracks for the week of <%=(t5.Fields.Item(“date”).Value)%></title>
<pubDate><%=(t5.Fields.Item(“date”).Value)%></pubdate>
<category>Top5</category>
<content:encoded><ol>
<li><%=(t5.Fields.Item(“songone”).Value)%></li>
<li><%=(t5.Fields.Item(“songtwo”).Value)%></li>
<li><%=(t5.Fields.Item(“songthree”).Value)%></li>
<li><%=(t5.Fields.Item(“songfour”).Value)%></li>
<li><%=(t5.Fields.Item(“songfive”).Value)%></li>
<%  IF TextShow <>”” THEN%>
<li>Guilty Pleasure: <%=(t5.Fields.Item(“guilty_pleasure”).Value)%>
</li><%ELSE%><%End If%></ol></content:encoded>
</item>

Now when this renders I can view the source and I’ll have all of my data nicely listed within <Item> Tags! (Note: the entire <content:encoded>tag must be on one line, it wouldn’t fit very nicely here). I went into the rendered HTML, removed the head and footer HTML leaving just the Items.

Next I created an XML file to be my importable RSS. I added the header and footer to the file:

<?xml version=”1.0″ encoding=”UTF-8″?>
<channel>
<title>Top5 High Rotation Tracks </title>
<link>http://arleym.com/</link>
<description>High rotation tracks of the week</description>
items will paste here…
</channel>
</rss>

Then it was a simple matter of pasting in the rows of <Item> after the RSS description, and uploading into WordPress.

The only snag I hit was when all of the dates were coming off as December 31, 1969. I quickly realized that the Date column in my database was actually a text field with entries in the format of “08.0-5.09″ (mm.dd.yy), which looked cool, but meant nothing to the database. A simple find and replace on the period and editing the field to be short-date resolved this issue nicely.

You can download my RSS Rendering page and my RSS headers here: RSS_Maker.aspRSS.xml

11 Responses to “Migrating data from ASP to WordPress”

  1. Since you did this a few years ago, Is there a better way to import an .ASP website into WordPress?

  2. ArleyM says:

    Sorry Dante! I haven’t had a need since then to really explore. WordPress is the most popular CMS on the planet, so there may be a plugin or post somewhere.

    Good luck!

  3. Cathy says:

    Hi, I wonder if I still can do that with external site (I don’t have the database for it). ?

  4. ArleyM says:

    Hey Cathy,
    If you don’t have a database it looks like you might have to do some miserable data harvesting… unless there’s a comment RSS feed?

  5. Ahmet says:

    Hi,
    First of all thanks for information.
    This article has written 5 years ago and i have doubt still working these code or hacks .
    I had asp data and i want to migrate my new wordpress website . There is any plugin or how can i migrate successfully this data to wordpress ?
    Thnx,
    Best Regards,
    Ahmet

  6. ArleyM says:

    Can you still make templates in your ASP site? If yes, I think there’s lots you could do, ripping off the above idea!

    First, go into WordPress and make a couple test items and do the native WP Tools > Export. This will produce an XML document that other WP sites could import. Copy the markup into an ASP template and have your ASP placeholders loop through the XML format in your .asp file!

    Once your ASP has spit out into this XML format copy that into a new file, save it as XML and import into WordPress. Make sense?

    • Ahmet says:

      Thnx for quick reply but ASP site isn’t working right now. I just have database of ASP site on my hand. How can i convert my database format to wordpress database format ? Or is it make sense if i try to import my asp database into the my new wordpress website’s sql ?
      Thnx

  7. ArleyM says:

    I’m a front end guy, so I don’t really know the ins and outs, but I think you’d be better off trying to get this database working with a local IIS server and printing out the data in a format that will export! Not sure how much work that is to set up, but you’ll be starting with a much cleaner set of data on the new site!

Leave a Reply