gpt4 book ai didi

c# - 不是保存 pdf 文件,而是显示目录列表

转载 作者:行者123 更新时间:2023-11-30 18:16:26 24 4
gpt4 key购买 nike

我在 MVC Controller 中使用简单代码通过 iTextSharp 在服务器上保存 pdf 文件:

var reportName = "reports/" + "report1.pdf";
var output = new FileStream(Server.MapPath(reportName), FileMode.Create, FileAccess.Write, FileShare.None);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
document.Add(new Paragraph("Hello World"));
document.Close();
return View();

但是报错

A default document for the desired URL is not configured and folder browsing is not enabled on the server.

然后我在 web.config 中设置这段代码

<directoryBrowse enabled="true" />

现在浏览器不再保存 pdf 文件,而是显示目录列表。

最佳答案

在根文件夹中放置一个虚拟的 default.aspx 文件,这在 MVC 工作时不会被使用,但可以解决这个问题。

关于c# - 不是保存 pdf 文件,而是显示目录列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46558840/

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