2012-08-17 79 views
0

我正在嘗試使用xmltextwriter並指定需要用於寫入的路徑。 我想這一點:c中的xmltextwriter路徑#

string path = "~/Uploads/site/" + Current.User.Id + .kml";         
XmlTextWriter xtr = new XmlTextWriter(path, System.Text.Encoding.UTF8); 

我想要的文件被保存在網站目錄內的上傳/網站/文件夾,但我得到了一個錯誤:

Could not find a part of the path 'c:\windows\system32\inetsrv\~\Uploads\site\16.kml'. 

我想知道如何將所需的路徑分配給xmltextwriter。 由於提前,Laziale

回答

2

使用服務器的說明。 MapPath方法來獲得正確的路徑。

string path = Server.MapPath("~/Uploads/site/" + Current.User.Id + ".kml"); 
0

這裏有一個錯誤

string path = "~/Uploads/site/" + Current.User.Id + .kml"; 

應該

string path = "~/Uploads/site/" + Current.User.Id + ".kml"; 

不過它不會工作,得到的回答是這個問題Map the physical file path in asp.net mvc

+0

第一線甚至不會編譯你得到這個錯誤。所以它不能是問題 – 2012-08-17 18:16:52

+0

@ L.B: - 謝謝,以後得到它.. :) – perilbrain 2012-08-17 18:19:45

0

,因爲你需要使用使用Server.Mappath 否則代碼試圖映射在您的PC,而不是服務器

string path = Server.MapPath("~/Uploads/site/" + Current.User.Id + ".kml");
+0

http://en.wikipedia.org/wiki/Keyhole_Markup_Language也對我來說是新的 – 2012-08-17 18:20:24

+0

哦,很高興知道! – TrizZz 2012-08-17 18:21:35