Hello,
Apologies for what might be a simple question; I'm getting back into coding after a seven year absence. Loving it, but everything is taking me so long!
Anyway, I'm trying to upload a file from the browser and then read it into an XmlDocument object on the server. Originally I cracked this by saving the file to disk, reading it into the XmlDocument object and then deleting the file. The only problem was that the delete action was trying to take place before the XmlDocument.Load action had completed. It felt like an ugly solution anyway, so it was happily abandoned.
Next effort was to read directly from the Request.Files[x].InputStream directly into the XmlDocument, but I'm having problems. The following code fails with a 'Root element is missing' error, but I know the XML is valid so it must be something else.
foreach (string file in Request.Files)
{
HttpPostedFileBase postedFile = Request.Files[file] as HttpPostedFileBase;
if (postedFile.ContentLength > 0) //if file not empty
{
//create an XML object and load it in
XmlDocument xmlProjPlan = new XmlDocument();
Stream fileStream = postedFile.InputStream;
byte[] byXML = new byte[postedFile.ContentLength];
fileStream.Read(byXML, 0, postedFile.ContentLength);
xmlProjPlan.Load(fileStream);
}
}
Any suggestions would be excellent, thank you.
Jonathan
You can read about progress at http://ablesoftware.blogspot.com/