Hi ,
iam having rdls report i want to send the particular report as an attachment to mail how to do this...
thanks in advance .
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 attend4days leftRegister
Manish Kumar ChoudharyRank #339 · 7.4K reputationPosted Feb 5, 2015, 2:00 AM EST
This also is very simple. It's done in 3 steps:
1: Instantiate your DataSet in code behind
2: Create a new report datasource against that DataSet
3: Add that datasource to the local report
Step 1: Instantiating your DataSet
// Assumes your xsd file is called MyDataSet
MyDataSetTableAdapters.YourTableAdapterHere ds = new MyDataSetTableAdapters.YourTableAdapterHere();
Step 2: Create a new report datasource against that DataSet
// Create a new report datasource item and setup its context
ReportDataSource rds = new ReportDataSource("MyDataSourceName", ds.GetData());
Step 3: Add that datasource to the local report
// Add it to the local report instance
viewer.LocalReport.DataSources.Add(rds);
So all in all it should look like this:
private void CreatePDF(string fileName)
{
// Setup DataSet
MyDataSetTableAdapters.YourTableAdapterHere ds = new MyDataSetTableAdapters.YourTableAdapterHere();
// Create Report DataSource
ReportDataSource rds = new ReportDataSource("MyDataSourceName", ds.GetData());
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;
// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "YourReportHere.rdlc";
viewer.LocalReport.DataSources.Add(rds); // Add datasource here
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download
}
Once pdf is ready send it to email id as attachment.
go through following links it will help you to send attachment with email id. Just in place of file name give this pdf file name.
https://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=7
http://www.codeproject.com/Tips/163829/Sending-an-Email-in-C-with-or-without-attachments