Pages

Men

rh

5/28/2013

How to Save the Export to Excel file from ReportViewer to Specific Folder in C#

ReportViewer1.ServerReport.ReportServerUrl = new Uri(System.Configuration.ConfigurationManager.AppSettings["ReportServerURL"].ToString());

ReportViewer1.ServerReport.ReportPath = "/" + System.Configuration.ConfigurationManager.AppSettings["ReportFolderName"].ToString() + "/MReport";
 

ReportParameter[] myparam = new ReportParameter[2];
 

myparam[0] = new ReportParameter("UserId", Session["UserID"].ToString().Trim());
 

myparam[1] = new ReportParameter("RNo", orderedItemsvalue.ToString());
 

ReportViewer1.ServerReport.SetParameters(myparam);
 

ReportViewer1.ServerReport.Refresh();


Warning[] warnings
;
string[] streamids;


string mimeType;


string encoding;


string extension;


String deviceInfo = null;


string ReportType = "Excel";
 


byte[] bytes = ReportViewer1.ServerReport.Render(ReportType, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);


File.WriteAllBytes(@"C:\Royalty\Report1.xls", bytes);

1 comment :