下载文件流对象不会打开"下载"对话框



嗯,我已经尝试了很多方法来解决这个问题,但都没有成功。

我开发了一个Reporting Service(2005)并部署了它。

这个报告将被每个访问基于框架3.5开发的网站的人使用(这是一个internet站点,所以不会被内部网访问)(但我认为框架的版本不是问题的根源)。

我在身份验证方面有其他问题,解决方法包括在我的网站上使用FileStream类。

ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://MyServer/ReportServer/ReportExecution2005.asmx";
arguments
byte[] result = null;
string reportPath = "/ReportLuiza/ReportContract";
string format = "PDF";
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "NMB_CONTRACT";
parameters[0].Value = txtNmbContractReport.Text;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, null);
rs.SetExecutionParameters(parameters, "pt-br");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
try
{
   result = rs.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);
   execInfo = rs.GetExecutionInfo();
}
catch (SoapException se)
{
    ShowMessage(se.Detail.OuterXml);
}
// Write the contents of the report to an pdf file.
try
{
    using (FileStream stream = new FileStream(@"c:report.pdf", FileMode.Create, FileAccess.ReadWrite))
    {
        stream.Write(result, 0, result.Length);
        stream.Close();
    }
}
catch (Exception ex)
{
    ShowMessage(ex.Message);
}

对于这段代码,我必须向其中提到的.asmx文件添加一个WebReference。

报告和网站都部署/发布在IIS 7.5版本的同一台服务器上。

是否有一种方法,用户可以选择在哪里保存。pdf文件?

任何帮助都将不胜感激。

如果你需要更多的信息来帮助我,尽管问。

您可能想要合并两个try-catch块:

ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://MyServer/ReportServer/ReportExecution2005.asmx";
arguments
byte[] result = null;
string reportPath = "/ReportLuiza/ReportContract";
string format = "PDF";
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = new ParameterValue();
parameters[0].Name = "NMB_CONTRACT";
parameters[0].Value = txtNmbContractReport.Text;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, null);
rs.SetExecutionParameters(parameters, "pt-br");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
try
{
   result = rs.Render(format, null, out extension, out encoding, out mimeType, out warnings, out streamIDs);
   execInfo = rs.GetExecutionInfo();
}
catch (SoapException se)
{
    ShowMessage(se.Detail.OuterXml);
}
// Write the contents of the report to an pdf file.
try
{
    /*
    using (FileStream stream = new FileStream(@"c:report.pdf", FileMode.Create, FileAccess.ReadWrite))
    {
        stream.Write(result, 0, result.Length);
        stream.Close();
    }
    */
    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment;filename="report.pdf"");
    Response.BinaryWrite(result);
    Response.Flush();
    Response.End();
}
catch (Exception ex)
{
    ShowMessage(ex.Message);
}

相关内容

  • 没有找到相关文章

最新更新