【问题标题】:xmltextwriter path in c#c#中的xmltextwriter路径
【发布时间】:2012-08-14 05:02:03
【问题描述】:

我正在尝试使用 xmltextwriter 并分配需要用于写入的路径。 我正在尝试这个:

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

我希望将文件保存在网站目录中的 uploads/site/ 文件夹中,但出现错误:

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

我想知道如何将所需的路径分配给 xmltextwriter。 在此先感谢 Laziale

【问题讨论】:

    标签: c# asp.net xml xmltextwriter


    【解决方案1】:

    这是一个错误

     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中说明了

    【讨论】:

    • 第一行甚至无法编译。所以这不是问题
    • @L.B :- 谢谢,后来知道了.. :)
    【解决方案2】:

    使用 server.MapPath 方法获取正确的路径。

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

    【讨论】:

      【解决方案3】:

      您收到此错误是因为您需要使用 Server.MapPath 否则代码会尝试映射到您的电脑而不是服务器上

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-15
        • 1970-01-01
        • 1970-01-01
        • 2010-11-02
        相关资源
        最近更新 更多