narasiman rao

narasiman rao

  • NA
  • 519
  • 767.1k

how to send mail the excel data from the folder

Aug 25 2016 8:48 AM
My code as follows

SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
DataSet ds = new DataSet();
cmd.CommandText = "select * from Empdetails";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
using (System.IO.StreamWriter fileOutput =
new System.IO.StreamWriter(@"C:\Users\God\Desktop\DataDump\Excel.xls"))
{
while (reader.Read())
{

for (int i = 0; i < reader.FieldCount; i++)
{
fileOutput.AutoFlush = true;
fileOutput.Write(reader[i].ToString() +"\t");
}
fileOutput.Write("\n");
}
}
sqlConnection.Close();
}

when i execute the above code select * from Empdetails ouput is saved in the below folder

C:\Users\God\Desktop\DataDump\Excel.xls


i want to send the above excel file to send mail.

for that how can i do in asp.net using c#

What I have tried:

how to send mail the excel data from the folder.

Answers (4)