Breaking News

Editors Picks

Thursday, February 2, 2012

In asp.net Sending Attachments Directly From a FileUpload

if (FileUpload1.HasFile)
{
    string toAddress = "to_mailid";
    string fromAddress = "your_mailid";
    string mailServer = "smtp.smtpservername.com";
    MailMessage myMailMessage = new MailMessage();
    myMailMessage.To.Add(toAddress);
    myMailMessage.From = new MailAddress(fromAddress);
    myMailMessage.Subject = "Test Message";
    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
    Attachment myAttachment = new Attachment(FileUpload1.FileContent,fileName);
    myMailMessage.Attachments.Add(myAttachment);
    SmtpClient mySmtpClient = new SmtpClient(mailServer);
    mySmtpClient.Send(myMailMessage);
}
Read more ...

In Asp.net Quick Wayto Filling a DataTable or DataSet the


private DataTable GetDataTable()
    {
        string sql = "SELECT recID,Main_Node_Name,IsActive from  ea_treeview";
        using (SqlConnection myConnection = new SqlConnection(connectionString))
        {
            using (SqlCommand myCommand = new SqlCommand(sql, myConnection))
            {
                myConnection.Open();
                using (SqlDataReader myReader = myCommand.ExecuteReader())
                {
                    DataTable myTable = new DataTable();
                    myTable.Load(myReader);                  
                    return myTable;
                }
            }
        }
    }
Read more ...

Contact Us

Name

Email *

Message *