Hi all,
I have a AsyncFileUpload control where I have everything working perfectly. However, I am saving the filename to an xml file as an image list to display in a GridView.
The only problem I am having is that no matter what I do the xml element being created is duplicated. Below is my code behind for AsyncFileUpload with the XmlDocument statement. Anyone have any idea how I can stop this from happening?
I know it has something to do with being in the AsyncFileUpload code because the xml works fine when tested elsewhere.
Thanks!!
Here is what happens with the xml doc. Notice I get 2 elements created...
<?xml version="1.0" encoding="utf-8"?>
<ImageLinks>
<ImageLink>~/Images/Uploads/ATT-Ad-1B.PNG</ImageLink>
<ImageLink>~/Images/Uploads/ATT-Ad-1B.PNG</ImageLink>
</ImageLinks>
here is my code behind in c#...
protected void Page_Load(object sender, EventArgs e)
{
AsyncFileUpload1.UploadedComplete += new EventHandler<AsyncFileUploadEventArgs>(AsyncFileUpload1_UploadedComplete);
AsyncFileUpload1.UploadedFileError += new EventHandler<AsyncFileUploadEventArgs>(AsyncFileUpload1_UploadedFileError);
}
void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + lblUploadStatus.ClientID + "\").innerHTML = '~/Images/Uploads/" + Path.GetFileName(e.FileName) + "';", true);
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("~/xml/ImageLinksList.xml"));
XmlElement imagelinkElem = doc.CreateElement("ImageLink");
imagelinkElem.InnerText = "~/Images/Uploads/" + Path.GetFileName(e.FileName);
doc.DocumentElement.PrependChild(imagelinkElem);
doc.Save(Server.MapPath("~/xml/ImageLinksList.xml"));
string savePath = MapPath("~/Images/Uploads/" + Path.GetFileName(e.FileName));
AsyncFileUpload1.SaveAs(savePath);
}
void AsyncFileUpload1_UploadedFileError(object sender, AsyncFileUploadEventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "error", "top.$get(\"" + lblUploadStatus.ClientID + "\").innerHTML = '<img src='../Images/design/status-red-check- unavailable.jpg' style='vertical-align:middle' /> Error: " + e.StatusMessage+ "';", true);
}