我有一个像这样的 XMLFile.xml
<?xml version="1.0" encoding="utf-8" ?>
<items>
<pdf ID="121">
<URL>www.google.co.in</URL>
</pdf>
</items>
我有具有路径的文件上传控件。当我单击保存时,它会更改相对于该 ID 的 URL 属性。
我有一个像这样的 XMLFile.xml
<?xml version="1.0" encoding="utf-8" ?>
<items>
<pdf ID="121">
<URL>www.google.co.in</URL>
</pdf>
</items>
我有具有路径的文件上传控件。当我单击保存时,它会更改相对于该 ID 的 URL 属性。
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("XMLFile.xml"));
if (FileUpload1.HasFile)
{
try
{
//string file = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(FileUpload1.FileName);
string filepath = Path.GetFullPath(FileUpload1.FileName.ToString());
Label1.Text = filepath;
XmlNodeList nodeList = xmlDoc.SelectNodes("/items/pdf[@ID='121']");
// update MainCategory
nodeList[0].ChildNodes[0].InnerText = Label1.Text;
// Don't forget to save the file
xmlDoc.Save(Server.MapPath("XMLFile.xml"));
Response.Write("XML File updated!");
}
catch (Exception ex)
{
Label1.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}