Scott Hanselman

Migrating Content from Random Blogs to DasBlog

September 23, '05 Comments [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 = 
BlogDataServiceFactory.GetService(AppDomain.CurrentDomain.BaseDirectory,null);
    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))
    {
        conn.Open();
        using(OleDbCommand newsCmd = new OleDbCommand("select * from News",conn))
        {
            using (OleDbDataReader reader = newsCmd.ExecuteReader())
            {
                while(reader.Read())
                {
                    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 :
blogText.Substring(0,Math.Min(20,blogText.Length)));
                    entry.Content = blogText.Replace("\r\n","<br>");
                    entry.EntryId = blogId.ToString();
                    entry.Categories = "main;old site";
                    entry.Author = "Ernie";
                    dataService.SaveEntry(entry);
                }
            }
        }
 
        using(OleDbCommand newsCmd = new OleDbCommand("select * from comments",conn))
        {
            using (OleDbDataReader reader = newsCmd.ExecuteReader())
            {
                while(reader.Read())
                {
                    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;
                    dataService.AddComment(comment);
                }
            }
        }
    }

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Jakob Nielsen at Corillian Connect

September 21, '05 Comments [8] Posted in Corillian
Sponsored By

Jakob Nielsen and Scott HanselmanI'm down in San Diego (Del Mar actually) at the Corillian Connect Conference (our annual Users' Conference). We had Jakob Nielsen give our keynote presentation. If you're not familiar with Jakob, you should be. He's a usability guru and has been since darn near the web's inception. He started the Nielsen Norman Group along with Donald Norman and added Bruce "Tog" Tognazzini a while back. They're giving a User Experience Conference in Boston and London this year that looks pretty amazing with talks from Amazon and Ebay.

I've been a fan since Jakob's original book Designing Web Usability. A classic and largely still valid today. He also runs UseIt.com. (No RSS though?)

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Weird Globe Folder in Visual Studio when opening a Web Project

September 20, '05 Comments [3] Posted in ASP.NET | Tools
Sponsored By

Crazyvdir

I was opening a Web Project that was part of a larger solution (SLN) file in Visual Studio.NET 2003 recently. A regular old directory with other directories below it was suddenly showing up with a strangee Globe Icon overlaid on the folder. I couldn't open the folder from the solution, but I could totally see its subfolders from with in Explorer. I was stymied. Totally confused. What is this icon trying to tell me? I looked in the .CSPROJ, the .SLN, everywhere.

I finally turned back on "Show Hidden Files" and noticed that a bunch of Front Page Schmutz(tm) was in that folder. Specifically the hidden "_vti_pvt" folder was causing Visual Studio to show this icon. I deleted it and hit the refresh button in the toolbar and all was good.

It reminded me that not everything is in the .csproj, .sln, .suo, .user files as much as I'd like to think so.

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

USB Wireless Security - Call For Plugins

September 20, '05 Comments [13] Posted in Coding4Fun
Sponsored By

WirelesspclockBryan and I are going to try and release an update to the USB Wireless Security Lock (Froogle) that I wrote about in Coding4Fun and Bryan wrote about in MAKE Magazine.

Consider this a Call For Plugins. If you've written a Plugin for USBWiSec, please let Bryan and I know so we can collect them into a USBWiSec-Contrib package and distribute them.

If you haven't heard about this little enterprise, well, click on the links above as we really think the potential for this device is great.

Remember, "USBWiSec - Replacement Sofware for your USB Wireless Security Lock: Sucking Way Less Since 2005!"

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Comcast adding CBS in HD in Portland on October 4th?

September 20, '05 Comments [1] Posted in Musings
Sponsored By

There's a rumor going around that Comcast will start broadcasting CBS in HDTV in Portland on October 4th. We shall see, but Cold Case in HDTV may find me watching CBS again.

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

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