2014-12-03 40 views
0

我使用itextsharp生成pdf文檔。我已經設置了一個string path。程序正常工作,但PDF文件保存在我的項目文件夾。我想將此路徑設置爲我的系統F磁盤。我目前的代碼是如何爲pdf創建設置server.mapath?

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

但它表明像它不是一個虛擬path..How錯誤我能做到這一點?

回答

0

全部MapPath does將您的IIS項目中的相對路徑轉換爲IIS項目部署到的絕對路徑。如果你要使用固定的路徑只需輸入一個固定的路徑

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

你也可以把它添加到the application settingsweb.config並從那裏讀取路徑。

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

Oh..Thank你。我沒有意識到這一點。 – 2014-12-03 05:40:58