Hi
I want to create upload file and i want to read the same file which is uploaded in c#.net
I wrote a code like this can u please check it.
private void btnUpload_Click(object sender, EventArgs e)
{
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
filename = openFileDialog2.FileName;
txtUpload.Text = filename;
}
else
{
MessageBox.Show("Please select a file");
}
// openFileDialog2.ShowDialog();
// txtUpload.Text = openFileDialog2.FileName;
//openFileDialog1.Filter = "Microsoft Excel Workbooks (*.xls)*.xls";
//if (openFileDialog1.ShowDialog() == DialogResult.OK)
//{
// sFileName = openFileDialog1.FileName;
//textBox1.Text = sFileName;
//}
//else
//{
// MessageBox.Show("Please select a file");
//}
}
private void btnSend_Click(object sender, EventArgs e)
{
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Book111.xlsx;Extended Properties=""Excel 12.0;HDR=YES;""";
//string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\book1.xlsx;Extended Properties=""Excel 8.0;HDR=YES;""";
//string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source= "+ filename + ";Extended Properties=Excel 8.0;HDR=YES;";
OleDbConnection conn = new OleDbConnection(connectionString);
string strSQL = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
DataTable dt = ds.Tables[0];
for (int ii = 0; ii < dt.Rows.Count; ii++)
{
DataRow dr = dt.Rows[ii];
string emailIdds1 = dr[0].ToString();
string[] emailIdfname = new string[10];
emailIdfname = dr[0].ToString().Split('@');
if (emailIdds1 != "")
{
MailMessage mailMsg = new MailMessage();
Attachment attch = new Attachment(sFileName);
mailMsg.From = new MailAddress(txtFrom.Text);
mailMsg.To.Add(emailIdds1);
mailMsg.Subject = txtSubject.Text;
mailMsg.IsBodyHtml = true;
//mailMsg.BodyEncoding = Encoding.UTF8;
string fname = "Dear " + emailIdfname[0].ToString() + "&Family," + "<html><body></br></body></html>";
mailMsg.Body = fname + txtMessage.Text;
mailMsg.Attachments.Add(attch);
mailMsg.Priority = MailPriority.Normal;
// Smtp configuration
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("srilekha.munigela@gmail.com", "suryam");
client.Port = 587; //or use 465
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
object userState = mailMsg;
try
{
//you can also call client.Send(msg)
//client.SendAsync(mailMsg, userState);
client.Send(mailMsg);
}
catch (SmtpException)
{
//Catch errors...
}
}
}
mailSucc.Visible = true;
}
am able to see the file and upload it but am unable to read the file can u please help me
as i wrote a code to split the name from "@"if numeric was present after the name it should not take it should read only the names not the numeric values can any one please help me by editing the code