我有一个XMLFile.xml 像这样
<?xml version="1.0" encoding="utf-8" ?>
<items>
<pdf ID="121">
<URL>www.google.co.in</URL>
</pdf>
</items>
我有fileupload控件有路径。当我点击保存它更改关于该ID的URL属性..
答案 0 :(得分:0)
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;
}
}
}