0

I am trying to use xmltextwriter and assign a path which needs to use for writing. I am trying this:

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

I want the file to be saved in the uploads/site/ folder within the website directory, but I am getting an error:

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

I would like to know how I can assign the desired path to the xmltextwriter. Thanks in advance, Laziale

Laziale
  • 7,965
  • 46
  • 146
  • 262

3 Answers3

2

Use server.MapPath method to get the right path.

  string path =  Server.MapPath("~/Uploads/site/" + Current.User.Id + ".kml");   
Waqar Janjua
  • 6,113
  • 2
  • 26
  • 36
0

Heres an error

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

should be

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

Still it wont work, and the answer is illustrated in this question Map the physical file path in asp.net mvc

Community
  • 1
  • 1
perilbrain
  • 7,961
  • 2
  • 27
  • 35
0

You get this error because you need to use Server.MapPath Otherwise the code is trying to map on your pc and not the server

string path = Server.MapPath("~/Uploads/site/" + Current.User.Id + ".kml");
TrizZz
  • 1,200
  • 5
  • 15