Reading a text file into a DataGridView using C# (Visual Studio 2005)

Being a website owner, I am always interested in how my site is performing in the search engines and, for the time being, Google is still my main focus. As I am busy learning C# using Visual Studio 2005 beta, I thought it may be useful to write an application that shows me what people searched for when they found my website on google. Please be aware that this is a quick 'n dirty and is NOT an example of good programming standards at all. It does demonstrate the following though:

The reason I use this "unprofessional method" of formatting a string into columns in the DataGridView is because I am reading my website's log file from Internet Information Services (IIS 5). This log file is seperated by spaces and not TAB characters or fixed length. If the string was TAB seperated of fixed length columns, it would be much easier. Also, you may have problems with this if you have spaces in your filenames on your site.

Up and running
To test the application, download the sample of my logfile and copy it to the Bin\Debug directory of your Visual Studio project.

Got questions about C# or .Net? Go to our Dot Net Forum.

Downloads
Example log file

Creating the application

Take note that you should replace all the code in the code editor and not just the form1_load method..

About the author
Dirk Wessels is a software developer and owner of www.getquotes-it.com. You may redistribute this article, but please keep this “About the author” section within the article together with an active link to www.getquotes-it.com