Wednesday, June 20, 2012

Error handing and sending mail from global.acax file


 void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
        Exception objErr = new Exception();
        objErr = Server.GetLastError().GetBaseException();
        StringBuilder strMailtext = new StringBuilder();
        strMailtext.Append("Page URL: " + Request.Url.ToString() + "<br>");
        strMailtext.Append("Error Source: " + objErr.Source + "<br>");
        strMailtext.Append("Error Description: " + objErr.Message + "<br>");
        strMailtext.Append("Stack Trace: " + objErr.StackTrace + "<br>");

        MailingUtility objMail = new MailingUtility();
        objMail.SetFromAddress("enquiries@sherforceplus.net");
        objMail.SetFromWhom("Shergroup Security");
        objMail.SetToAddress("a-kumar@sherforce.net");
        objMail.SetCCAddress("");
        objMail.SetMessageBody(strMailtext.ToString());
        objMail.SetSmtpClient("shermail");
        objMail.SendMail("", false);
    }

Tuesday, June 12, 2012

Add new column and its value in Dataset in c#


 dsLetters.Tables[0].Columns.Add(new DataColumn ("ClientRequirement"));
            foreach (DataColumn item in dsLetters.Tables[0].Columns)
            {
                if (item.ToString() == "ClientRequirement")
                {
                    dsLetters.Tables[0].Rows[0]["ClientRequirement"] = clientNeed.ToString();   
                }
            }