禁用对话框,该对话框提示“;打开/保存/取消”;用户从ASP.NET4.5C#网站选择PDF格式的SSRS2012报告
本文关键字:对话框 网站 NET4 ASP 选择 5C# PDF 报告 SSRS2012 格式 提示 | 更新日期: 2023-09-27 18:20:25
我需要绕过/禁用对话框,该对话框提示用户从ASP.NET C#站点为PDF格式的SSRS报告选择"打开"、"保存"或"取消"。
我能够做到以下几点:在C中从ASP.NET调用并呈现PDF格式的SSRS报告#将PDF报告保存在特定驱动器中,但不希望对话框提示"打开"、"保存"或"取消"。
我想禁用或绕过这个需要用户选择"打开"、"保存"或"取消"的对话框(试图避免这种额外的点击)。我的代码将读取保存的PDF文件并在浏览器中查看。我使用ReportViewer创建报告,然后以PDF格式呈现,所以它保存在C:''//PDFReports文件夹中。
如何强制"保存或取消"或绕过此对话框不显示?这是我的代码:
private void ShowReport()
{
try
{
string urlReportServer = "http://devSSRS//ReportServer";
ReportViewerSSRS.ProcessingMode = ProcessingMode.Remote; // ProcessingMode will be Either Remote or Local
ReportViewerSSRS.ServerReport.ReportServerUrl = new Uri(urlReportServer); //Set the ReportServer Url
ReportViewerSSRS.ServerReport.ReportPath = "/FinanceReports/GrossProfitReport"; //Passing the Report Path
//Creating an ArrayList for combine the Parameters which will be passed into SSRS Report
ArrayList reportParam = new ArrayList();
reportParam = ReportDefaultPatam();
ReportParameter[] param = new ReportParameter[reportParam.Count];
for (int k = 0; k < reportParam.Count; k++)
{
param[k] = (ReportParameter)reportParam[k];
}
//pass parmeters to report
ReportViewerSSRS.ServerReport.SetParameters(param); //Set Report Parameters
ReportViewerSSRS.ServerReport.Refresh();
//output as PDF
byte[] returnValue = null;
string format = "PDF";
string deviceinfo = "";
string mimeType = "";
string encoding = "";
string extension = "pdf";
string[] streams = null;
Microsoft.Reporting.WebForms.Warning[] warnings = null;
returnValue = ReportViewerSSRS.ServerReport.Render(format, deviceinfo, out mimeType, out encoding, out extension, out streams, out warnings);
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=GrossProfitReport.pdf");
Response.BinaryWrite(returnValue);
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
string FileName = @"C/ReportFilesPDF/"
FileStream fs = File.OpenWrite(FileName);
fs.Write(returnValue, 0, returnValue.Length);
fs.Close();
}
catch (Exception ex)
{
throw ex;
}
}
private ArrayList ReportDefaultPatam()
{
string selYear = (string)(Session["Year"]);
string selMonth = (string)(Session["Month"]);
string selGroup1 = (string)(Session["Segment"]);
ArrayList arrLstDefaultParam = new ArrayList();
arrLstDefaultParam.Add(CreateReportParameter("Year", selYear));
arrLstDefaultParam.Add(CreateReportParameter("Month", selMonth));
arrLstDefaultParam.Add(CreateReportParameter("Segment", selSegment));
return arrLstDefaultParam;
}
private ReportParameter CreateReportParameter(string paramName, string pramValue)
{
ReportParameter aParam = new ReportParameter(paramName, pramValue);
return aParam;
}
非常感谢您的帮助!!非常感谢,chaydeee
我为此使用了一个助手函数,并将传递SSRS url(带有渲染标记)和文件服务器目标。
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
'loRequest.Credentials = New System.Net.NetworkCredential("username", "password", "domain")
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub