如何为pdf创建设置server.mappath?

时间:2014-12-03 05:26:36

标签: c# pdf-generation

我使用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\");

但它显示的错误就像它不是虚拟路径。我该怎么做?

1 个答案:

答案 0 :(得分:0)

所有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>          
相关问题