Category Archives: Asp.Net

Check if the string end or start with any of the element in an array in C#

We may have used normal EndsWith() extension for the string to check if the string ends with a specific string or character. But, did you ever encountered a situation where you have to check if the string ends with or starts with any of the given strings, may be an array ?. Well I have, and so I wrote an extension for checking if a string ends or starts with any of the element in an array in C#. Once you have this in a static class, say StringExtensions, you can use it in your application if you have access to that class.

Well, I did not use much comments since as you can see its almost self explanatory. Quite simple to do, right ?. Happy coding guys.

Minify Css using C#

Here I am sharing a simple code to minify css to optimize the size and make the page load faster. Long css files are always a headache when comes to the page load speed. This will fix that issue for an extent

Happy Coding

Calculate age of a person from his date of birth

When I was working with a project, I wanted to calculate age using date of birth provided. So I implemented a method and made it an extension to datetime object. I am sharing this code with you guys

Happy Coding

Create a month dropdown list easily

Here I am introducing a useful extension method for Dropdownlist in asp.net and C#. Creating Month list in a dropdown list.

Simple, easy and clean. Happy Coding

How to get notified via email on error in your application

I am presenting here a simple but useful way to get notified via email, when ever an error is happening in your asp.net application with out using try catch. I am creating a httpmodule in app_code for notifying errors. Here is the code for the module.

I am using my “EmailSender” utility for sending emails here. You can find that here. Using this method, first you should create a folder “MailTemplates” in your root folder and add a html template file for “ErrorNotification.htm” in that folder. You can get the referance for creating the html email template from here. Now add the following code in EmailSender class

You are almost done. Now we need to add the module to our application’s configuration file. Add the following configuration value to your web.config, inside system.web and system.webserver (for IIS7).

Hurrey, so it is done. Cheers and Happy coding.