Thursday 18 April 2013

How can setup a friendly email name in the MailSetting section of web.config?


Well, in code you need to put the sender's name in quotes, followed by the e-mail address.

new SmtpClient(...).Send("\"John Smith\" jsmith@somewhere.com", ...);
And...it looks like you can encode it into the attribute too...

<smtp from="&quot;John Smith&quot; &lt;jsmith@somewhere.com&gt;">

CompareValidator for “dd/mm/yyyy” format

By default the ASP.Net CompareValidator does not work for dd/mm/yyyy format hence we will need to change the Culture property of the page to en-GB in the @Pagedirective of the ASP.Net Web Page as show below

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Request.aspx.cs" Inherits="Request" Culture = "en-GB"  %>

Wednesday 17 April 2013

Standard Date Format in c#


DateTime dtStartDate, dtEndDate;
        string uname = null;
        string strStartDate, strEndDate;

   if (txtStartDate.Text == "")
            {
                strStartDate = string.Format("{0:d}", Convert.ToDateTime("01-01-1900"));
            }
            else
            {
                strStartDate = string.Format("{0:d}", Convert.ToDateTime(txtStartDate.Text));
            }
            if (txtEndDate.Text == "")
            {
                strEndDate = string.Format("{0:d}", Convert.ToDateTime("01-01-2500"));
            }
            else
            {
                strEndDate = string.Format("{0:d}", Convert.ToDateTime(txtEndDate.Text));
            }

            dtStartDate = Convert.ToDateTime(strStartDate);
            dtEndDate = Convert.ToDateTime(strEndDate);



  strStartDate= dtStartDate.ToString("dd/MM/yyyy", new CultureInfo("en-US"))
  strEndDate= dtEndDate.ToString("dd/MM/yyyy", new CultureInfo("en-US"))

Friday 5 April 2013