gpt4 book ai didi

c# - 将定义的名称放在 asp.net c# 的 reportviewer PDF 中

转载 作者:太空宇宙 更新时间:2023-11-03 14:54:16 24 4
gpt4 key购买 nike

我有这段代码,它的作用是为我生成一个PDF 或 EXCEL。我如何定义 moneto 以可视化或下载给我这个名字。例子EXCEL.excel 或 PDF.pdf我正在寻找定义固定名称示例的方法rodo.pdf 或 rodo.excel

public ActionResult print(ParametrosGeneral param, string id, FormCollection TipoReporte)
{

string Format = "pdf";
// string Format = "excel";


LocalReport lr = new LocalReport();
string path = System.IO.Path.Combine(Server.MapPath("~/Reportes"), "Libro.rdlc");

if (System.IO.File.Exists(path))
{
lr.ReportPath = path;
}
else
{
return View("Index");
}

ReportDataSource rd = new ReportDataSource("DSLibro", LibroVenta(4, 2018).Tables[0]); //here returns my query with the meters for 4 and 2018 that I send
lr.DataSources.Add(rd);

string reportType = Format;
string mineType;
string encoding;
string fileNameExtension;

string deviceInfo =
"<DeviceInfo>" +
"<OutputFormat>" + Format + "</OutputFormat>" +
"<PageWidth>11in</PageWidth>" +
"<PageHeight>8.5in</PageHeight>" +
"<MarginTop>0,787402in</MarginTop>" +
"<MarginLeft>0,787402in</MarginLeft>" +
"<MarginRight>0,787402in</MarginRight>" +
"<MarginBottom>0,787402in</MarginBottom>" +
"</DeviceInfo>";

Warning[] warnings;
string[] streams;
byte[] renderedBytes;

renderedBytes = lr.Render(
reportType,
deviceInfo,
out mineType,
out encoding,
out fileNameExtension,
out streams,
out warnings);

return File(renderedBytes, mineType);
}

最佳答案

按照这些思路尝试。文件名将是 somepdf.pdf

var cd = new System.Net.Mime.ContentDisposition
{
FileName = "somepdf.pdf",
Inline = true
};
Response.Headers.Add("Content-Disposition", cd.ToString());

return File(bytes, "application/pdf");

关于c# - 将定义的名称放在 asp.net c# 的 reportviewer PDF 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50414541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com