How to ‘Publish’ a Web Application in Visual Studio 2003

3 08 2010

If you’ve used later versions of Visual Studio for creating web applications, you will know that there is an option to ‘Publish’ your application which allows you to compile your application into only files needed to run the application (a good practice to use when putting your application online).

When it comes to Visual Studio 2003, there isn’t such an option but the functionality is still there, just masquerading under a different menu option!

When you have your project open, build it in ‘Release’ mode (it is not essential that it is built in ‘Release’ mode but I find there are performance improvements over building it in ‘Debug’ mode). Now select ‘Copy Project’ from the ‘Project’ menu along the top.


You will then be presented with the following pop-up dialog:


Here you give it a destination project folder (in my case, the same as the source project folder, but to a folder called ‘Published’), and a web access method. I choose to publish it to my local file system, and then upload it myself. You then choose to copy ‘Only files needed to run this application’ and click ‘OK’. If you now go to the folder which you chose in the ‘File Share’ path, you will have all the files you need to upload to put your web application online, the same as if you had ‘Published’ a web application in a later version of Visual Studio.

Date Manipulation in C#

30 03 2010

DateTime to String

When you have a DateTime object that you want to store or present as a string, I find the easiest way to format the date is as follows:

DateTime today = DateTime.Now;
string stDate = today.ToString("dd MMMM yyyy");

This code will return "30 March 2010". You can format it as you like using the ToString method, using the key string combinations for different ways of displaying days, months, year, minutes and seconds. I have linked to a useful site in a previous post that will give you the string combinations you can use, here’s the link again . The ones you will probably use most are under Custom Date Formatting on that site.

If you wanted to add the “th” after the date you could do the following:

DateTime today = DateTime.Now;
string stDate = String.Format("{0}th {1}", today.ToString("dd"), today.ToString("MMMM yyyy"));

This code will return “30th March 2010”.

Adding & Subtracting Days / Months / Years / Hours / Minutes / Seconds

There are methods available to add days, months and years to a DateTime object. AddDays(), AddMonths() etc. So if I wanted to show 6 months time, I would use the following code:

DateTime sixMonthsTime = DateTime.Now.AddMonths(6);
string stDate = sixMonthsTime.ToString("MMMM yyyy");

This code will return “September 2010”.

To subtract days, months, years etc, we use the same method. If I wanted to show 6 months ago, I would use the following code:

DateTime sixMonthsTime = DateTime.Now.AddMonths(-6);
string stDate = sixMonthsTime.ToString("MMMM yyyy");

This code will return “September 2009”.


This is all I have chance to write on this subject at the moment but I will add to this post whenever I get chance or come across something new.

String Formatting in C#

5 02 2010

I don’t have much to say in this post really. It’s all in the title and I’m going to point you to this brilliant post on SteveX Compiled. Whenever I need to check up on a string format, this is the place I go! 🙂

Mutex & Semaphore’s

19 01 2009

The difference between a mutex and a semaphore is something I often forget. So while this is fresh in my mind…

Mutex: Locks a critcal section of code when in use by a thread, and unlocks it only when that thread is complete. It works on a one out, one in system but only ever allows one thread at any time. If a thread tries to access the mutex when it is locked, it is forced to wait in a queue until it is unlocked.

Semaphore: A semaphore is an extension of a mutex and also locks a critical section of code when in use by a thread. However with a semaphore you can specify how many threads are allowed simultaneous access. For example, your semaphore allows 4 simultaneous threads. Each time a thread uses the semaphore, the semaphore decreases its counter by 1 until it is zero, at which point no more threads are allowed access and are forced to queue. When a thread finishes using the semaphore, the semaphore increaes it’s counter by one to allow the next thread in the queue access.

This site provided me with the best explanation:

Also, put even simpler by this site :

“A mutex allows one thread inside the critical section, a semaphore allows n threads in a critical section (when the number n is given as a parameter on the initialization).”