To create windows service get sql data to import excel sheet and send the data through outlook mail set a time?
Loading
To create windows service get sql data to import excel sheet and send the data through outlook mail set a time?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jignesh KumarRank #91 · 22.9K reputationPosted Feb 13, 2023, 11:58 PM EST
Hi Naveen,
Please refer this link which will help you,
https://www.c-sharpcorner.com/UploadFile/4b0136/sending-email-with-an-attached-file/
Rajeesh MenothRank #118 · 18.4K reputationPosted Feb 14, 2023, 12:44 AM EST
Hi Naveen,
You can go through my article, If doubt please reach out to me.
https://www.c-sharpcorner.com/UploadFile/2a6dc5/send-multiple-email-with-attachment-using-Asp-Net-with-C-Sharp/
Note: complete code I have given in my article attachment section.
Vishal YelveRank #178 · 13.6K reputationPosted Feb 14, 2023, 1:17 AM EST
Hi Naveen,
try this hope this will help
int count = 0; string connectionstring ="Server=(local);initial catalog=Test;Trusted_Connection=True"; SqlConnection sqlConnection =new SqlConnection(connectionstring); SqlCommand cmd =new SqlCommand(); SqlDataReader reader; DataSet ds =new DataSet(); cmd.CommandText ="select * from Empdetails"; cmd.CommandText +=" where shifttype = @par "; cmd.Parameters.Add("@par", SqlDbType.Int).Value = j; cmd.CommandType = CommandType.Text; cmd.Connection = sqlConnection; sqlConnection.Open(); reader = cmd.ExecuteReader(); string filePath =@"C:\Users\God\Desktop\DataDump\" + j + "Excel.xls"; System.IO.StreamWriter sw_In =new System.IO.StreamWriter(filePath); if (reader.HasRows) { while (reader.Read()) { if (count == 0) { for (int i = 0; i < reader.FieldCount; i++) { sw_In.AutoFlush =true; sw_In.Write(reader.GetName(i) +"\t"); } sw_In.Write("\n"); count = 1; } for (int i = 0; i < reader.FieldCount; i++) { sw_In.AutoFlush =true; sw_In.Write(reader[i].ToString() +"\t"); } sw_In.Write("\n"); } sw_In.Dispose(); } reader.Close(); sqlConnection.Close(); MailMessage mis =new MailMessage(); mis.From =new MailAddress("[email protected]","Report"); mis.IsBodyHtml =true; mis.To.Add("[email protected]"); mis.CC.Add(new MailAddress("[email protected]")); mis.Subject ="Data Dump Report"; mis.Attachments.Add(new Attachment(filePath,"application/vnd.ms-excel")); SmtpClient smtpserver =new SmtpClient("smtp.gmail.com"); smtpserver.Credentials =new System.Net.NetworkCredential("[email protected]","12345"); smtpserver.Host ="smtp.gmail.com"; smtpserver.Port = 587; smtpserver.EnableSsl =true; smtpserver.Send(mis);Vishal JoshiRank #377 · 6.7K reputationPosted Feb 14, 2023, 2:59 AM EST
Hello Naveen,
Please check the below article to create window service runs at a specific time.
https://www.c-sharpcorner.com/article/create-window-service-in-net-core/
For importing data from excel to SQL server please refer below article.
https://www.c-sharpcorner.com/article/import-excel-data-into-sql-table-using-sqlbulkcopy-in-c-sharp/
Thanks