I have been testing my code to save into an XML file locally and it is working fine. However i have just uploaded it to my server and it is not working. I changed the path to the path of the xml file but still no luck. This is my local code…
public void AddNodeToXMLFile(string XmlFilePath, string NodeNameToAddTo)
{
//create new instance of XmlDocument
XmlDocument doc = new XmlDocument();
//load from file
doc.Load(XmlFilePath);
//create main node
XmlNode node = doc.CreateNode(XmlNodeType.Element, "Level", null);
//create the nodes first child
XmlNode mapname = doc.CreateElement("map");
//set the value
mapname.InnerText = mapsave.Value;
// add childes to father
node.AppendChild(mapname);
// find the node we want to add the new node to
XmlNodeList l = doc.GetElementsByTagName(NodeNameToAddTo);
// append the new node
l[0].AppendChild(node);
// save the file
doc.Save(XmlFilePath);
}
protected void btnSave_Click(object sender, EventArgs e)
{
if (mapsave.Value.ToString() == "")
{
lblResult.Text = lblError.Value;
}
else
{
AddNodeToXMLFile("C:\\Users\\Glen.Robson\\Documents\\Visual Studio 2010\\Projects\\Project1\\Project1\\Scripts\\UserMaps.xml", "TileMaps");
}
}
So when i uploaded to the server i changed the path of AddNodeToXMLFile() to:
"http://www.mydomain.com/Scripts/UserMaps.xml"
But this does not work… Can anyone tell me what the file path should be?
You cannot change the path to a URL… the code on the server still needs to know the physical path to the file on the server. It cannot work out where the file is based on a URL.
Why don’t you use an application specific path…
Then in your function, you need to “map” the virtual path into an actual physical path on the server…
Also, you need to make sure that permissions are setup on the server correctly – meaning that the process that the ASP.NET application is running on IIS with, has the ability to write to the directly