I have a scenario where a user will upload an XML file开发者_StackOverflow中文版, and I'd like to add the file to a table in my database. The hard part, though, is that I need to parse the file and then add some of the information to some different tables.
Every example showing how to get an XML file use a URI to get the file, but how do you get the file straight from either the database or, preferably, from the asp:FileUpload control on postback?
Take a look at the XmlDocument.Load method:
XmlDocument myDoc = new XmlDocument();
myDoc.Load(fu_MyFile.FileContent);
I did this a while ago with ColdFusion and haven't had to do it yet with Asp.Net, but the basic theme is the same.
- Save the file in the code behind.
- Load the file via an Xml trick, XmlDocument like Abe posted or XElement.Load(file)
- Parse it how you'd like.
- Delete the file.
精彩评论