我一直在测试我的代码以在本地保存到 XML 文件中,并且工作正常。但是我刚刚将它上传到我的服务器并且它无法正常工作。我将路径更改为 xml 文件的路径,但仍然没有运气。这是我的本地代码...
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");
}
}
因此,当我上传到服务器时,我将 AddNodeToXMLFile() 的路径更改为:
"http://www.mydomain.com/Scripts/UserMaps.xml"
但这不起作用......谁能告诉我文件路径应该是什么?