[C#] Using Nini .NET Configuration Library

When developing a desktop application, there will be times when you want to store settings for your program. A database is one option, but on Windows, you might just wish to have your settings stored in an INI file. One way to work with an INI file in C# is with the Nini Library. This makes it quite easy to read from and write to an INI file.

Let’s get started.

After installing the library, we’ll need to set our namespace.

What will our INI file look like? Something like this:

For my application, I decided to make a class devoted to the configuration file. So, let’s define that and a few other variables.

Now that we have our variables declared, let’s create a couple of useful methods.

These two methods will update the INI file with new settings, should we change them in our program. Of course, if we make these changes, they need to be saved. Thankfully, we can declare something in our constructor (which we will write a little later) that will auto-save our changes as we make them.

Now, let’s create a pair of methods to return the data. This will be useful in our program when we need to use these settings.

With these methods, we now have a basic class for handling a configuration file. All that is left is our constructor.

But before we get to the constructor, there is something else I created. What if our INI file doesn’t exist? I decided that I would make a function to create a default INI file, should the old one not exist anymore. This is also useful if we want to distribute our program without an INI file.

We can do a check when we initialize our class that will check to see whether or not this file exists. If not, we’ll create it so we can work with it.

That makes this our constructor:

Our whole class thus looks like this:

That’s how simple it can be to work with your own INI files in C#.

Did you find this useful? Let me know in the comments!

Next Apple OS Revealed: Mountain Lion Coming Soon

In a spectacular quiet announcement Thursday, Apple revealed details of its upcoming operating system, Mountain Lion.  Typically, such an announcement is brought along with a huge presentation. Instead, Apple had a small gathering of media for a private event.

Their site showcases several upcoming features for Mountain Lion. Again, it looks like iOS and OSX are being brought closer together. What changes are coming?

For starters, things that people are used to with iOS devices (iPhone, iPod Touch, and iPad) are coming to OS X. These include notes, reminders, Game Center, and the notification center.

But the biggest improvement is one that was already released. Messages Beta is available for OS X Lion users to download (requires 10.7.3 patch). This is essentially an upgrade/update to iChat. Besides changing the name to Messages, an important feature has been added, one that I figured would be coming: The ability to iMessage your friends. Yes, you can chat from your Mac to someone with an iPad or iPhone. And any iMessages sent to you are automatically synced to each of your devices, so you can pick up the conversation where you left off.

I’ve already been using Messages and can say that iMessage integration is pretty cool. It isn’t perfect and is a little buggy, but by the time Mountain Lion is released this summer, I think the chat experience will be more perfected.

For a video overview of OS X Mountain Lion, watch the video below.


Other good articles on Mountain Lion:

MacWorld, Mashable, Gizmodo, Ars Technica, EnGadget, Today’s iPhone

How-To: Fix Trend Micro Add-In Missing in Microsoft Outlook

This post will be the first of many that I plan to write that detail some bugs, technical issues, and problems I’ve had to fix in some way.

I had a friend come to me with an issue: Every time they started up Outlook, they received an error saying that the Trend Micro add-in was missing. Reinstalling Trend Micro did not correct this issue. I thought this was going to be an easy fix. I started by trying to disable the plugin via the Tools/Options area of Outlook. Unfortunately, there was no listing for anything from Trend Micro. Yet, Outlook seemed to think there was something.

One solution I found online was to delete the extend.dat file that Outlook uses to know which extensions are installed. On Windows XP, that is found at:

C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\

On Windows Vista and Windows 7:


Once this file was deleted, I reopened Outlook. Outlook rebuilt the file, and we never saw an issue with a ghost Trend Micro plugin again.

Did you find this solution helpful? Or did you find another solution to this problem? Leave a comment!

Working with DataTable in C#

One thing I’ve had to do lately is learn some C#. I will admit that it isn’t the language I would prefer to work with during the week, but it does help me become more versatile when it comes to application development.

Working with C#, I had to take data and enter it into a data grid. Being that I still consider myself a C# newbie, I figured this was something I might as well learn to use.

In the end, creating a data table in C# isn’t that difficult. In this example, I’ll be taking data from a Microsoft Access database and entering it into a DataTable object.

First, let’s define our DataTable and its columns.

Now, while it isn’t necessary, I like having temporary variables to hold data from a database before entering it into our table. For what we have, that would be:

All that is left to get is the data itself. Assuming we’re getting it from some kind of database, we can get the information in a while loop and add all of the data into the table.

Now we have our data in the DataTable. All that is left is to output it. For this, I have a DataGridView object in my form called myDataGrid.

And that’s all there is to using a DataTable in C#.

Have you worked with DataTables? Submit your experiences and comments below!