1
I am making a series of reports which I need to generate the PDF and save to the server, for the user to download. I cannot use the mode atatchment
and neither inline
. Because the user has the option to create multiple reports and download later.
Follow the passage of conversion:
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>PDF</OutputFormat>" +
" <PageWidth>21cm</PageWidth>" +
" <PageHeight>29.7cm</PageHeight>" +
" <MarginTop>0.1in</MarginTop>" +
" <MarginLeft>0in</MarginLeft>" +
" <MarginRight>0in</MarginRight>" +
" <MarginBottom>0.1in</MarginBottom>" +
"</DeviceInfo>";
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = mimeType;
// HttpContext.Current.Response.AddHeader("content-disposition", "C:\\ExportedReport." + "PDF");
HttpContext.Current.Response.AddHeader("content-disposition", ("atatchment; filename=ExportedReport." + "PDF"));
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
It didn’t work. I added this line below the line : byte[] bytes = Reportviewer1.LocalReport.Render("PDF",
– Germano Sampaio
Now you are giving the error:{"Access to the path 'C: Exportedreport.PDF' is denied." }. if it was a Txt file I would have to create it, as it is a pdf , I don’t know what to do
– Germano Sampaio
Probably the user used by IIS or IIS Express is not allowed to write to
C:
. If IIS, create a folder underC:
and permission for the user IIS_IUSRS– Marcus Vinicius