Attaching an Event Handler

Whenever I need to attach an event handler, usually I use one of these methods, a delegate, anonymous method, or lambda expression. For complex events (more than 3 lines of code), I create a separate method. If the method is short, I use anonymous method. But if the event is just one line, I use…


How to Give Authenticated Users or Everyone Access to Your Share Programmatically

Another follow-up from my previous article, Programmatically Configuring Permissions on a Share, David B asked a question, how to share a folder to Everyone, instead of to a specific users. This article will answer that question, based on the code on my previous article. That is an interesting question, since ‘Everyone’ can be replaced with…


How to Programmatically Modify the IIS Virtual Directory

If you have more than a dozen web servers in a cluster with identical setting, and you need to update the virtual directory, it is much more convenient to write a simple program to update it. This example shows how to do it. In this case, this snippet will change the physical path of a…


Concatenating A List of Elements into A String, From [A] [B] [C] into "A, B, C"

This is a quite common problem, there is a list of strings, and you need to concatenate them with a delimiter, let says a comma. There are several different approaches to this problem. Before .Net era, I use for loop, and check if the loop counter is not pointing to the last element in the…


Generating P/Invoke Signature

I have been using PInvoke.Net for long time. I discovered a tool, P/Invoke Interop Assistant. It is very cool. Not only it can gives you the managed wrapper around the native Windows API, it also gives you the ability to generate the unmanaged signature for your managed assemblies. The best thing, the source code is…


Workaround to deserialize ‘True’, ‘False’ using XmlSerializer

This is the scenario, system A is taking an xml from system B. System A will deserialize the xml into an object. Unfortunately, a dev in system B decides that System.Xml namespace is evil and construct the xml using StringBuilder. In one of the element, the dev call ToString() method of a boolean variable. The…


C# 3.0 Automatic Property

C# introduces a number of syntactic sugar, including Automatic Property link. A question was asked, why is this useful, what is the advantage of this approach compared to exposing the field as public field? The advantage of the automatic property is that while you have a much cleaner code, you still have encapsulation, you can…


How to Add Command Line Support with Your .MSI

One of the requirements in building setups was to allow the Operations team to execute the .msi file from the command line. GUI is not for expert! 🙂 If you are familiar with Visual Studio setup, each of the UI element has a property, and you pass this property to your custom action, or use…


Fixing the Issue that Does Not Exist

I spent some time planning on improvements that I wanted to do on one of our project. I reviewed the code that I notice a place where I think I could improve the performance by avoiding locking. So I wrote the code, and tested it, works great, the new non-locking algorithm works fine. Then when…


IE 8 RC 1 is Now Available for Download

I downloaded and installed IE 8 RC 1 on my machine. It works really well, the performance improvement is significant. I would encourage you to give it a try, Disclaimer, this is an Release Candidate, not RTM. There could be some issues, but overall, this is really good.