2012-08-17 3 views
0

J'essaie d'utiliser xmltextwriter et d'affecter un chemin qui doit être utilisé pour l'écriture. J'essaie ceci:xmltextwriter path in C#

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

Je veux que le fichier soit enregistré dans le uploads/site/dossier dans le répertoire du site, mais je reçois une erreur:

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

Je voudrais savoir comment je peux assigner le chemin désiré au xmltextwriter. Merci à l'avance, Laziale

Répondre

2

serveur utilisation. La méthode MapPath pour obtenir le bon chemin.

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

Heres une erreur

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

doivent être

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

encore il ne fonctionnera pas, et la réponse est illustrée dans cette question Map the physical file path in asp.net mvc

+0

La première ligne ne serait même pas compiler. donc il ne peut pas être le problème –

+0

@ L.B: - Merci, je l'ai eu plus tard .. :) – perilbrain

0

Vous obtenez cette erreur, car vous devez utiliser Server.MapPath Sinon, le code tente de la carte sur votre PC et non le serveur

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

http://en.wikipedia.org/wiki/Keyhole_Markup_Language aussi nouveau pour moi –

+0

Ohh Bon à savoir! – TrizZz