我已閱讀了關於此問題的多篇文章,但它們都以它不工作或以vb.net結尾。以編程方式將C#中的SSRS報告另存爲
我目前有:
該報告通過這使得他們作爲一個PDF,當用戶點擊一個按鈕,將它們保存在下載文件夾中的網址訪問,這些被賦予通用名稱,如OrderReport,OrderReport(1)...等等。
var orderNum = 1;
"http://Server/ReportServer_Name/Pages/ReportViewer.aspx?%2fOrderReport&rs:Command=Render&OrderID=" + orderNum + "&rs:ClearSession=true&rs:Format=PDF"
什麼我試圖acheive:
- 我想用C#如果可能,本報告取,然後爲PDF文件指定一個名稱,並將其保存在正確的位置。
因此,例如,我想這份報告在臨時文件夾中保存現在的「C:\ TEMP」的名稱訂單ID-1。我使用C#
我已經在服務引用添加到我使用所謂ReportTestings所以引用
using ReportTestings;
和Web引用URL項目:
http://Server/ReportServer_Name/ReportExecution2005.asmx
(去除實際名稱爲安全原因)
所以基於上述所有這些信息可能有人指向我正確的方向還是舉個例子的代碼的一部分,三江源所有看到這篇文章,或幫助
使用此代碼我得到這個錯誤:(+ E
{"Access to the path 'C:\\Program Files (x86)\\IIS Express\\report1one.pdf' is denied."} System.Exception {System.UnauthorizedAccessException})
代碼:
ReportExecutionService rs = new ReportExecutionService();
rs.Credentials = new NetworkCredential("username", "password", "domain");
rs.Url = "http://Server/ReportServer_Name/reportexecution2005.asmx";
// Render arguments
byte[] result = null;
string reportPath = "/Invoice";
string format = "PDF";
string historyID = null;
string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
// Prepare report parameter.
ParameterValue[] parameters = new ParameterValue[3];
parameters[0] = new ParameterValue();
parameters[0].Name = "InvoiceID";
parameters[0].Value = "2";
DataSourceCredentials[] credentials = null;
string showHideToggle = null;
string encoding;
string mimeType;
string extension;
Warning[] warnings = null;
ParameterValue[] reportHistoryParameters = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
rs.SetExecutionParameters(parameters, "en-us");
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);
try
{
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
execInfo = rs.GetExecutionInfo();
Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.OuterXml);
}
// Write the contents of the report to an MHTML file.
try
{
FileStream stream = File.Create("report1one.pdf", result.Length);
Console.WriteLine("File created.");
stream.Write(result, 0, result.Length);
Console.WriteLine("Result written to the file.");
stream.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
我一直在嘗試這個,但當我試圖將報告保存在任何地方時,我一直在訪問被拒絕。看看上面的例子現在添加,如果你可以通過訪問被拒絕的錯誤,這將有助於很多 – Crezzer7
在我提供的鏈接(https://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx)非常簡單,你看過嗎? –
是的,仍然存在被拒絕的問題 – Crezzer7