我正在使用这两个功能从一个页面下载2个不同的文件。
RenderReport用于下载已发送给它的rdlc报告,即LocalReport和DOWNLOAD()用于下载pdf文件。
现在的问题是,其中一个不同时工作。如果我下载RDLC报告,那么pdf下载不起作用或反过来。它抛出异常,即浏览器检测到重复标题等。
public void Download()
{
try
{
MemoryStream memStream = Export(html); // returns a memory stream object
byte[] bytesInStream = memStream.ToArray();
Response.Clear();
Response.ContentType = "application/pdf";
Response.Headers.Remove("content-disposition");
Response.AddHeader("content-disposition", "attachment; filename=name_you_file.pdf");
Response.BinaryWrite(bytesInStream);
Response.End();
Response.Flush();
}
catch (Exception)
{
throw;
}
}
private void RenderReport(LocalReport localReport)
{
try
{
//Give the collection a name (EmployeeCollection) so that we can reference it in our report designer
var reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
var deviceInfo =
string.Format("<DeviceInfo><OutputFormat>{0}</OutputFormat><PageWidth>8.27in</PageWidth><PageHeight>11.69in</PageHeight><MarginTop>0.3in</MarginTop><MarginLeft>0.3in</MarginLeft><MarginRight>0.3in</MarginRight><MarginBottom>0.3in</MarginBottom></DeviceInfo>", reportType);
Warning[] warnings;
string[] streams;
//Render the report
var renderedBytes = localReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
//Clear the response stream and write the bytes to the outputstream
//Set content-disposition to "attachment" so that user is prompted to take an action
//on the file (open or save)
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=Tender." + fileNameExtension);
Response.BinaryWrite(renderedBytes);
Response.End();
Response.Flush();
}
catch (Exception ex)
{
}
}