Вот упрощенная версия моего кода:
Код: Выделить всё
public ActionResult DownloadMergedPdf(List Ids, string Title, string reportName)
{
List fileArray = new List();
if (Ids != null && Ids.Count > 0)
{
try
{
int totalReports = Ids.Count;
int currentReportIndex = 0;
foreach (var id in Ids)
{
currentReportIndex++;
int i = int.Parse(id);
string SoCt = db.PhieuThu.Where(x => x.Id == i).Select(x => x.SoPhieu).FirstOrDefault().ToString();
// Set the report path and parameters
reportViewer.ServerReport.ReportPath = "/DemoReport/" + reportName;
ReportParameter[] parameters = new ReportParameter[2];
parameters[0] = new ReportParameter("Id", id, true);
parameters[1] = new ReportParameter("Title", Title, true);
reportViewer.ServerReport.SetParameters(parameters);
// Render the report to PDF
byte[] pdfBytes = reportViewer.ServerReport.Render(
"PDF",
null,
out string mimeType,
out string encoding,
out string fileNameExtension,
out string[] streams,
out Microsoft.Reporting.WebForms.Warning[] warnings
);
if (pdfBytes != null && pdfBytes.Length > 0)
{
fileArray.Add(pdfBytes);
}
else
{
throw new Exception($"Error rendering report for ID {id}: PDF bytes are null or empty.");
}
}
var mergedBytes = MergePdfBytes(fileArray);
return File(mergedBytes, "application/pdf", "MergedReport.pdf");
}
catch (Exception ex)
{
// Log the error for debugging
System.Diagnostics.Debug.WriteLine("Error in DownloadMergedPdf: " + ex.Message);
return new HttpStatusCodeResult(500, "An error occurred while creating the PDF file: " + ex.Message);
}
}
else
{
return RedirectToAction("Index", "Home");
}
}
- Разрешения, предоставленные пользователю ' IIS APPPOOL\YourAppPoolName» недостаточно для выполнения этой операции. (rsAccessDenied)
- Путь к элементу «/DemoReport/» недействителен. Полный путь должен содержать менее 260 символов; применяются другие ограничения.
- Как я могу гарантировать, что приложение имеет необходимые разрешения для доступа к отчетам с помощью ReportViewer?
- Какие действия следует предпринять, чтобы избежать ошибки rsInvalidItemPath при настройке пути к отчету?
- Есть ли требуются ли на сервере какие-либо конкретные настройки для успешного рендеринга и загрузки объединенных PDF-файлов с помощью ReportViewer?
Будем очень признательны за любые рекомендации и предложения!
Подробнее здесь: https://stackoverflow.com/questions/791 ... sp-net-mvc