Category Archives: Asp.Net

How to load a csv file to a data table

Here is a simple and optimized method to load a csv file to a datatable object. I have gone through many situations when we can not store data in a database, instead have to store in an xml or csv file. This method helped managing those situations effectively. Here is the code for accomplishing this.

Here is how we are going to use it

How to create a simple captcha validation in asp.net

We often see captcha validation in number of sites outthere. Earlier, when I started surfing in web, I wondered how they are created. But now I have answer for that.I am presenting you before, a simple method to implement a captcha validation in your asp.net websites (PHP folks, cheer up. I am working on a similiar thing in php too.). In this method I am using System.Drawing namespace in C#. First I am going to create a generic handler which will render the captcha image.Look at the code below

And now we are going to implement the validation. Create an aspx page, add add an img tag and for the src attribute,give the path to the handler. See below.

And now it’s time for testing the validation. Code behind will look like this.

And we are done! The validation form will look like this. Download sample project Try this and let me know the feedback.Cheers

How to use Compression method in asp.net to speed up website

Common questions related to performance issues of websites

  1. How to improve website performance ?
  2. How to speed up website ?
  3. How to compress webpages
  4. What are the methods to improve page loading speed
  5. How to optimize webpages

I googled alot to find some good and easy method to speed up my websites, already i have optimised all my css and scripts and ofcourse images. So now i need to compress the webpages. And i come up with this solution. It is very simple. This method uses gzip/deflate encoding to compress the webpages. First, create a global.asax file. Now add the following code into that file.

Now upload the file to root of your website.And you are done. But before doing this ensure that you have optimized your css, js and images also. Only then you can feel the change

Cheers

How to convert normal date time to relative

How to make a normal date like “12/05/2011” to “Some days some hours and some seconds ago”
Here is the answer. We have seen dates in vairous formats, some of you may noticed in facebook or orkut, how they show times. They show relative date and time.
Here is the code for doing it. It is an extension to DateTime Object.

And you are done!. Now you can use the code like this

Cheers

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.

Usage:

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

Cheers