im trying to create an xml file and then save it to a file location...
string xmlPath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "cities.xml";
XDocument doc = new XDocument(
new XElement("Cities",
new XElement("City",
new XAttribute("id", gid),
new XElement("CityName", cityname))));
doc.Save(xmlPath);
the problem is that its not being saved to the location specified...
Try to use the System.IO.Path.Combine
method to make sure you a) have the necessary backslash between the directory and the file name, and to b) make sure you don't have multiple of those:
string xmlPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"cities.xml");
Also: maybe your user account doesn't have the permissions to write to that directory. Try using something like Isolated Storage or some other directory you're 100% sure that the user is allowed to write to.
The code looks fine and when I tested it locally it worked. Make sure that xmlPath
points to a directory where the current user has write permissions. As a side note it would be better to use Path.Combine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With