Social Icons

Pages

Saturday, January 14, 2012

Retrieving Assembly Attributes

To retrieve the value set in the Assembly Attributes in the AssemblyInfo.cs file, use the code below. The example shows retrieving the AssemblyName attribute.
void displayAssemblyName()
     {
 System.Reflection.Assembly thisAssembly = this.GetType().Assembly;
 object[] attributes = thisAssembly.GetCustomAttributes  (typeof(AssemblyNametAttribute), false);
           {
this.labelName.Text = ((AssemblyNametAttribute)attributes[0]).Name;
            }
       }


Email validation

Here's a small method for Email validating in C#. It may save you some time.
public static bool MailValidation(TextBox textBox)
        {
            try
            {
                string pattern = @"^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$";
                System.Text.RegularExpressions.Match match = Regex.Match(textBox.Text.Trim(), pattern, RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    return true;
                }
                else
                {
                    if (textBox.Text != string.Empty)
                    {
                        MessageBox.Show("This is a valid email address.");
                        return false;
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return false;
        }