我有一个网站可以从报表服务器生成报表。我需要通过URL将参数传递给报表服务器。
这是我得到的回应。然后我创建了一个本地文件流来存储响应中的数据。但问题是,当我尝试访问本地文件以与另一个文件合并时,它返回错误
“D:\ Work \ Report \ Reporting Site 31012017 \ DAnalytics.Web \ reports \ 147b9b1f-bb42-4353-bda2-490fb8c6a026.pdf未找到文件或资源”
void GenerateMinMaxWebReport(GenerateReportArgs args)
{
long totalBytesRead = 0;
const int blockSize = 65536;
Byte[] buffer = new Byte[blockSize];
StringBuilder _url = new
StringBuilder(ConfigurationManager.AppSettings["SSRS_SERVER"])
.Append("?").Append(ConfigurationManager.AppSettings["SSRS_PATH"])
.Append("dailyreport_minmax&rs:Command=Render&rs:format=PDF&rc:Toolbar=False&rc:Parameters=False")
.Append("&ReportID=").Append(hdnReportID.Value);
if (args.FromDate.HasValue)
_url.Append("&FromDate=").Append(args.FromDate.Value.ToString("MM/dd/yyyy"));
if (args.ToDate.HasValue)
_url.Append("&ToDate=").Append(args.ToDate.Value.ToString("MM/dd/yyyy"));
_url.Append("&DoAutoPick=").Append(args.DoAutoPick.ToString());
_url.Append("&DoSummary=").Append(args.DoSummary.ToString())
.Append("&IsSummaryOnly=").Append(args.SummaryOnly.ToString())
.Append("&CH4RangeCharts=").Append(args.DisplayCH4Charts.ToString());
string FileName = System.Guid.NewGuid().ToString() + ".pdf";
string Dir = Server.MapPath("~/reports/");
string FileFullName = Path.Combine(Dir, FileName);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(_url.ToString());
req.UseDefaultCredentials = true;
req.Timeout = Timeout.Infinite;
req.PreAuthenticate = true;
req.KeepAlive = true;
req.Credentials = new System.Net.NetworkCredential(
ConfigurationManager.AppSettings["SSRS_USERNAME"],
ConfigurationManager.AppSettings["SSRS_PASSWORD"],
ConfigurationManager.AppSettings["SSRS_DOMAIN"]);
try
{
using (HttpWebResponse httpResponse = (HttpWebResponse)req.GetResponse())
{
using (Stream responseStream = httpResponse.GetResponseStream())
{
using (FileStream localFileStream = new FileStream(FileFullName, FileMode.Create))
{
int bytesRead;
while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) > 0)
{
totalBytesRead += bytesRead;
localFileStream.Write(buffer, 0, bytesRead);
}
}
}
}
}
catch (Exception e)
{
// MessageBox.Show(e.ToString());
}
_Files.Add(0, FileFullName);
}
这就是我通过URL传递参数并创建本地文件的方式。
public string MergeDocs(Dictionary<int, string> _Files)
{
string _CombinedPDFPath = string.Empty;
if (_Files.Count > 0)
{
_CombinedPDFPath = Path.Combine(Path.GetDirectoryName(_Files[0]), "DR_" + DateTime.Now.ToString("ddMMHHmmss") + ".pdf");
//Step 1: Create a Docuement-Object
Document document = new Document();
try
{
//Step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(_CombinedPDFPath, FileMode.Create));
//Step 3: Open the document
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int n = 0;
int rotation = 0;
//Loops for each file that has been listed
for (int iCount = 0; iCount < _Files.Count; iCount++)
{
//The current file path
// string filePath = sourcefolder + filename;
// we create a reader for the document
PdfReader reader = new PdfReader(_Files[iCount]);
//Gets the number of pages to process
n = reader.NumberOfPages;
int i = 0;
while (i < n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(1));
document.NewPage();
//Insert to Destination on the first page
if (i == 1)
{
Chunk fileRef = new Chunk(" ");
fileRef.SetLocalDestination(_Files[iCount]);
document.Add(fileRef);
}
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0,
reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
}
}
}
catch (Exception e) { throw e; }
finally
{
document.Close();
//AddIndex(_CombinedPDFPath);
}
}
return _CombinedPDFPath;
}
这是我用来合并文档的代码。
有谁知道为什么会发生这个错误以及如何解决这个错误?
所有帮助都表示赞赏。
答案 0 :(得分:0)
文件是否存在于该路径中? 如果是这样,是否可以使用其他用户帐户编写,以便读者没有读取权限?