2012-08-17 77 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