Posted by: Terry Nederveld | July 7, 2009

Creating an Application with a File Association

In order to have your application open and process a file that has an associated file type you will need to change the main entry point for the application (by default it is Program.Main()). First you will need to give the method a string array input variable.

static void Main(string[] args) { }

Now that you have this changed your application will now accept attributes at startup. Before we proceed you will need to add a public string variable to your form’s code-behind.

public string SelectedFile;

Once you have that in place you are able to go back to your Main method and add the following code which will look for the arguments coming into the application and process them appropriately.

string SelectedFile = null;
if (args.Length > 0)
     SelectedFile = Convert.ToString(args[0]);

At this time you have the SelectedFile variable filled with the first position of the array (the actual path of the file) if and only if the length of the array is greater than zero. Continue on loading the application and make sure you set the public string variable of the form.

Form1 app = new Form1();
app.SelectedFile = SelectedFile;

In order for your application to actually do anything with this file location that was passed into your application you will need to modify your Load event on the form. Below is the code that I used.

private void Form1_Load(object sender, EventArgs e)
     if (SelectedFile != null)
          //do something with the file.

That is all there is to it, fairly easy and straight forward and no real hoops to jump through.

Posted by: Terry Nederveld | July 7, 2009

Windows Application ComboBox

For the longest time I struggled between the combo boxes in a windows application versus an ASP.NET  web application. Since you can add an object to the item collection of the combo box, this is what I do. I created a class called ComboBoxItem that I use when adding items to the item collection of the combo box.  Below is the code for the class:

public class ComboBoxItem
       private string _name;
       private int _value;
       public ComboBoxItem(string name, int value)
              _name = name;
              _value = value;
       public override stringToString()
              return _name;
       public int Value
              get { return _value; }
       public string Name
              get { return _name; }

Now that we have the ComboBoxItem class created all you need to do is populate it and add it to the ItemCollection of the combo box.

cbLookups.Items.Add(new ComboBoxItem(“Test Item”, 0));

Now that we have populated the combo box with items, how do we get the Id (0) out of the selection made by the user. That is fairly easy also, since we now have the class.

ComboBoxItemcI = (ComboBoxItem)cbLookups.SelectedItem;
int iLookupID = cI.Value;

You can create any object to use, as long as you override the .ToString() with what you want to display in the combo box. For instance, I created another class that holds Active Directory information and the .ToString() concatenated the Given Name and Surname to display the AD users name in the combo box. I also added more properties to the class that would hold other AD information so I wouldn’t have to query AD a second time after allowing the end user the ability to select an AD user from the combo box.

This is fairly straight forward code and should convert to VB.Net easily. At a later date I will come back through and add in the VB code for it also.

Posted by: Terry Nederveld | July 2, 2009

Lytebox and Internet Explorer 8

If you haven’t noticed, lytebox doesn’t work properly with IE8. The background overlay and the border color of the popup do not show. I have read a few blogs about how people are changing the cascading style sheet (CSS), in my search I found it wasn’t the CSS that was the issue. It is the actual script. Here is what I did to get it working properly.

The issue originated from this line:

this .ie = (document.all && !window.opera) ? true : false;

Here is how I got it to work:

this .ie = (document.all && !window.opera) ? checkVersion() : false;

I added the “checkVerzion()” function right before the LyteBox.prototype.initialize function.

function checkVersion() {
         if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
                  var ieversion = new Number(RegExp.$1)
                  if (ieversion >= 8 )
                           return false;
                  else if (ieversion < 8 )
                           return true;
         return false;

After adding that code to the lytebox.js file, the LyteBox popup works properly in IE8 and continued working properly in all other tested browsers (IE7, Firefox 3.0.11, Safari 4.0, Chrome 2).

Amended July 7, 2009:

I had a person ask for the source of the JavaScript file, so I posted it on my SkyDrive. You can download it from here:

Amended February 24, 2011:

We now have a community project up on GitHub. See my blog post at:

Posted by: Terry Nederveld | April 22, 2009

Martial Law & Habeas Corpus

I would like pose a question to all those that are following what is going on with the government. I do not have an answer, but would like to see what your thoughts are.

What would happen if martial law was declared? What would happen if habeas corpus was suspended?

Posted by: Terry Nederveld | March 30, 2009


I started reading the book “The 5000 Year Leap” and have discovered some interesting things within the first 30 pages that I thought I would pass along.
Jefferson said it was immoral for one generation to pass on the results of its extravagance in the form of debts to the next generation. He wrote: “… we shall all consider ourselves unauthorized to saddle posterity with our debts, and morally bound to pay them ourselves; and consequently within what may be deemed the period of a generation, or the life [expectancy] of the majority.” (Ibid., 13:358.)
Samuel Adams said they had done everything possible to make the ideas of socialism and communism unconstitutional. Said he:

The Utopian schemes of leveling [re-distribution of the wealth] and a community of goods [central ownership of the means of production and distribution], are as visionary and impractical as those which vest all property in the Crown. [These ideas] are arbitrary, despotic, and, in our government, unconstitutional. (William W. Wells, The Life and Public Service of Samuel Adams, 3 vols. [Boston: Little, Brown and Company, 1865], 1:154.)

More to come as they are discovered in this book. I may end up buying a copy so I can highlight and write in it.

Posted by: Terry Nederveld | August 29, 2008

Searching with Google

Today I heard of a person that spent the past three days searching Google for a piece of software that could do what they were looking for. I am not saying that they didn’t know what they were doing with the powerful tool called Google.

But, most people don’t know how to use Google and not get thousands of results. So I decided today to write up some tips that I use when searching Google. And my blog is born.

First off, most people don’t know or don’t realize that you can search within a single site, for instance, if I know that I only want to search the MSDN site for content about LINQ I would type “LINQ”. This search only brings up pages from the MSDN site that contain LINQ.  You can use the “site:” term in Google for any site and it will only search that site.

Now what if I want to be more specific and put two or more keywords into the search, many people would type the two words. The only bad thing at least for me, I am normally looking for both those terms in one page, with using a space it looks for either and both terms. So you normally end up with a ton of pages that are not relevant to what you are searching for. I use a plus sign in between the two keywords like this: “C# + LINQ”into Google and in doing that Google will make sure that both my keywords show up in the page.

Another thing that most people don’t realize is when they are searching for a phrase. Let’s use “Customize Windows Home Server” for an example. If you type a phrase into Google without quotes around it, Google will try to find a page with any of the words or all of the words. Not necessarily in the correct order. If you put quotes around something Google will only return pages that contain that exact phrase. Let’s look at the difference in results between the two methods.

As you can see with this search there is a HUGE difference in the results that are returned to you. When searching be smart and don’t waste your time, the Internet is big but you can really narrow it down when you know how to use Google correctly.

« Newer Posts