【问题标题】:How to set server.mapath for pdf creation?如何为 pdf 创建设置 server.mapath?
【发布时间】:2014-12-03 05:26:35
【问题描述】:

我正在使用 itextsharp 生成 pdf 文档。我设置了string path。程序正常工作,但 pdf 文件保存在我的项目文件夹中。我想将此路径设置为我的系统F 磁盘。我当前的代码是

 string path = Server.MapPath("Reports");
 PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path +""+name+".pdf", FileMode.Create));
 System.Diagnostics.Process.Start(path + "name.pdf");

如何设置string path = Server.MapPath("Reports");到我的系统F盘。我应用了像

这样的海峡路径
string path = Server.MapPath(@"F:\reports\");

但它显示错误,例如它不是虚拟路径..我该怎么做??

【问题讨论】:

    标签: c# pdf-generation


    【解决方案1】:

    MapPath 所做的只是将 IIS 项目中的相对路径转换为 ​​IIS 项目部署到的绝对路径。如果要使用固定路径,输入固定路径即可

    string path = @"F:\reports\";
    

    您也可以将其添加到 web.config 中的 the application settings 并从那里读取路径。

    //In your code
    var path = WebConfigurationManager.AppSettings["savePath"];
    
    <!-- in web.config -->
    <appSettings>
      <add key="savePath" value="F:\reports\"/>
    </appSettings>          
    

    【讨论】:

    • 哦..谢谢。我不知道这个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2015-03-10
    相关资源
    最近更新 更多