Category Archives: Csharp

How to create an image handler to resize external images on the fly

This post is about creating an image handler to resize external images on the fly. I got code to resize images with in our server, but i was in need to resize external images in the fly. So I modified the code. Lets create a generic handler file first, named ImageHandler.ashx.


We can do this with our internal images also by changing the GetImage() function a little bit.
Hope you like this, enjoy coding


How to upload files to ftp using and C#

We all know how to upload files to ftp via ftp client. But as programmers there will be certain situations when we need to upload files to ftp from our application. It is quite simple. The following C# example uses a simploe approach to upload files to an ftp location.

How to remove all event handlers from a control – C# winforms

A few days ago I was stuck in a problem. I was in need of removing certain events from controls that i have on my form. I spend almost 3 hours googling for a suitable code and I found this article in stackoverflow. It helped me alot.

The code I got from there was meant to remove click event from a button. I need to remove double click events from some panels and click events from some buttons. So i made a control extension, which will remove all eventhandlers for a certain event.

Now, the usage of this extenstion.

If you need to remove click events from a button,

If you need to remove doubleclick events from a panel,


Calculating first and last day of a month using and C#

Some days ago I needed to calculate the first day and last day of a month for one of the project I am working on. I got some ideas while googling, and I wrote a code.The method I am using is simple.Here is the code

So, here I’m using the AddDays method which can add given number of days to the current date. Using today.Day I’m extracting the current date day as integer value, which is 21 in my example. The tricky part here is that I’m adding with the AddDays method total of 21-1 = 20 and using the minus sign, it’s getting 20 days back (instead of 20 days forward).

-(today.Day – 1) is actually -(21-1) = 01-07-2010 17:27:50

Next, the calculation of the LastDay

With today = today.AddMonths(1) I’m adding one month plus to the current date.
Before adding, the today value was {21-07-2010 17:27:50} – after adding +1 month, the today value is {21-08-2010 17:27:50}.
Then, with the last line, the trick is very similar to the firstDayDate calculation, we only go in minus to the number of days got from the today.Day integer value. We do not add today.Day-1 here because if we do, we will get the first day of the next month (so you know one more thing now – how to get the first day of the next month 🙂 ).
The lastDay value will be 31-07-2010 17:27:50


How to convert text to speech in WPF

Before the birth of Windows Presentation Foundation(WPF), it was considered difficult to work with multimedia in applications. But now it became simple. Microsoft provides a new speech API (SAPI) for Windows Vista and later. It allows developers to build speech enabled applications. Simply add a reference to System.Speech and include the following code to your project.

Cool, isn’t it ?