Posts Tagged: Util-a-day

UAD5 – Append Directory

When creating various file explorer for asp.net I generate thumbnails and put these in a hidden thumbs folder. This little routine just slips in a directory at the end so c:\images\file.jpg becomes c:\images\thumbs\file.jpg. /// <summary> /// Adds the passed directory…Continue Reading →

UAD4 – Is Valid Email

A simple regex to see if a string is in a valid email format public static bool IsValidEmail(string email) { string expression = @"^(([^<>()[\]\\.,;:\s@\""]+" + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@" + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+" + @"[a-zA-Z]{2,}))$"; Regex re = new Regex(expression); if (re.IsMatch(email)) return…Continue Reading →

UAD3 – Enum to ListItemCollection

Converts an enum to a ListItemCollection so users can select an option from an enum. Just cast it back like so: (enumToUse)Enum.Parse(typeof(enumToUse), DropDownList.SelectedItem.Value)(enumToUse)Enum.Parse(typeof(enumToUse), DropDownList.SelectedItem.Value) /// <summary> /// Converts enum to ListItemCollection /// </summary> /// <param name="EnumToUse"/>Type of enum to use…Continue Reading →

UAD2 – Label Change

Server controls are great but sometimes you need to change labels for different users, like change ‘Product Name’ to ‘Book Title’ when all they sell is books. You can create a load of properties or just use a simple util…Continue Reading →

Utility Function A Day.

I have a little plan to release a small code snippet a day till I run out or get bored 😉 Just simple little utility functions that do things like check phone numbers, credit cards etc. Nothing special but just…Continue Reading →