Friday, 30 May 2014

Send mail with Attachment File

public static string SendMailWithFile(string ToEmail, string subject, string body, string attachmentFilename)
    {
        try
        {
            string MailSenderEmail = ConfigurationManager.AppSettings["SenderEmail"].ToString();
            string MailSenderPwd = ConfigurationManager.AppSettings["SenderPwd"].ToString();
            string smtpInfo = ConfigurationManager.AppSettings["smtpInfo"].ToString();
            SmtpClient smtpClient = new SmtpClient();
            NetworkCredential basicCredential = new NetworkCredential(MailSenderEmail, MailSenderPwd);
            MailMessage message = new MailMessage();
            MailAddress fromAddress = new MailAddress(MailSenderEmail);

            // setup up the host, increase the timeout to 5 minutes
            smtpClient.Host = smtpInfo;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = basicCredential;
            smtpClient.Timeout = (60 * 5 * 1000);
            message.From = fromAddress;
            message.Subject = subject;
            message.IsBodyHtml = true;
            message.Body = body;
            message.To.Add(ToEmail);
            message.Bcc.Add("dharmendrap2@gmail.com");
            if (!string.IsNullOrEmpty(attachmentFilename))
            {
                Attachment attachment = new Attachment(attachmentFilename, MediaTypeNames.Application.Octet);
                ContentDisposition disposition = attachment.ContentDisposition;
                disposition.CreationDate = File.GetCreationTime(attachmentFilename);
                disposition.ModificationDate = File.GetLastWriteTime(attachmentFilename);
                disposition.ReadDate = File.GetLastAccessTime(attachmentFilename);
                disposition.FileName = Path.GetFileName(attachmentFilename);
                disposition.Size = new FileInfo(attachmentFilename).Length;
                disposition.DispositionType = DispositionTypeNames.Attachment;
                message.Attachments.Add(attachment);
            }
            smtpClient.Port = 587;
            smtpClient.EnableSsl = true;
            smtpClient.Send(message);
            return "1";
        }
        catch (Exception ex)
        {          
            throw ex;
        }
    }

Sunday, 18 May 2014

Best convert code string to datetime and To convert the string you parse it into a DateTime value, the format that into a string

using System.Globalization;
string date = "20100102";
   DateTime datetime = DateTime.ParseExact(date, "yyyyMMdd", CultureInfo.InvariantCulture);

string newFormat = DateTime.ParseExact(theDate, "dd'.'MM'.'yyyy", CultureInfo.InvariantCulture).ToString("yyyy'/'MM'/'dd")

Tuesday, 13 May 2014

alter table column when new column

IF NOT EXISTS(SELECT * FROM sys.columns
        WHERE [name] = N'columnName' AND [object_id] = OBJECT_ID(N'tableName'))
BEGIN
    ALTER tableName ADD [columnName] [ntext] NULL
END

Friday, 9 May 2014

Error : Directory Listing Denied This Virtual Directory does not allow contents to be listed.


This is a common Error frequented by many of us when we try to configure the IIS to work for our websites. This error indicates that the IIS could not locate the intial load document of your website or web application. This is generally due to our oversight while configuring IIS.
By default, the following documents are listed in IIS.

  • Default.asp
  • Default.htm
  • index.htm
  • iisstart.asp
To fix this error, we need to follow the following steps.
1. Open IIS via Control Panel or by entering "inetmgr" at run(Start).
2. Open your Computer details(default local Computer)
3. Expand "Web Sites" -> "Default Web Site"
4. Locate your project folder under this and right-click and select properties
5. Locate the "Documents" tab under these properties.
6. Under the "Enable Default Document" section, press the ADD button.
7. In the new pop-up window enter the name of your startup document with its extension.(Login.aspx)
8. Select the newly added value in Default Document section and set it priority level by using the arrows on the left side on the window.
9. Press the OK button and refresh IIS.
10. Right click your project and select browse.