开发者

Parse XML file uploaded through asp:FileUpload

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.

  1. Save the file in the code behind.
  2. Load the file via an Xml trick, XmlDocument like Abe posted or XElement.Load(file)
  3. Parse it how you'd like.
  4. Delete the file.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜