I am trying to read few xml files in a directory using fileinfo class.
Dim di As New IO.DirectoryInfo(Server.MapPath("OniFiles"))
Dim aryFi As IO.FileInfo() = di.GetFiles("*.xml")
Dim fi As IO.FileInfo
For Each fi In aryFi
Dim filename As String
Dim filepath As String
filename = fi.Name
filepath = Server.MapPath("Files\" & filename)
Dim xmldoc As XmlDocument = New XmlDocument
xmldoc.Load(filepath)
-----------Then parsing each xml file to get the node details and saving them to database---
--------------------Then setting the xmldocument to Nothing.
xmldoc = Nothing
next
Actually the files are too big.They were about 250 MB.When i am reading the first file it looks ok sometimes.But,when control tries to read second file it is throughing the exception.
Strangely, sometimes it is happening when i am trying to read the first file itself.
Could anyone please help me how to read those large files without getting that error.
.Net 2.0xml.vb.xmlfileinfofile.ioxml parsing errorFile IOXML .Net VBfile open in asp.net apps
adityaraj
Member
15 Points
28 Posts
A first chance exception of type 'System.OutOfMemoryException' occurred in System.Xml.dll Error
Jun 20, 2010 10:49 PM|LINK
Hi,
I am trying to read few xml files in a directory using fileinfo class.
Dim di As New IO.DirectoryInfo(Server.MapPath("OniFiles"))
Dim aryFi As IO.FileInfo() = di.GetFiles("*.xml")
Dim fi As IO.FileInfo
For Each fi In aryFi
Dim filename As String
Dim filepath As String
filename = fi.Name
filepath = Server.MapPath("Files\" & filename)
Dim xmldoc As XmlDocument = New XmlDocument
xmldoc.Load(filepath)
-----------Then parsing each xml file to get the node details and saving them to database---
--------------------Then setting the xmldocument to Nothing.
xmldoc = Nothing
next
Actually the files are too big.They were about 250 MB.When i am reading the first file it looks ok sometimes.But,when control tries to read second file it is throughing the exception.
Strangely, sometimes it is happening when i am trying to read the first file itself.
Could anyone please help me how to read those large files without getting that error.
.Net 2.0 xml .vb .xml fileinfo file.io xml parsing error File IO XML .Net VB file open in asp.net apps
adityaraj
Member
15 Points
28 Posts
Re: A first chance exception of type 'System.OutOfMemoryException' occurred in System.Xml.dll Err...
Jun 21, 2010 02:06 AM|LINK
Hi all,solution for the above thread is use a xmltextreader to read the large file and load it into the xmldocument
Dim reader As New XmlTextReader(filepath)
Dim xmldoc As XmlDocument = New XmlDocument
xmldoc.Load(reader)
Yannick86
Member
565 Points
366 Posts
Re: A first chance exception of type 'System.OutOfMemoryException' occurred in System.Xml.dll Err...
Dec 19, 2012 02:01 PM|LINK
I have the exact same issue, but the above solution does not do the trick for me.
Anything else I can try?
Thanks in advance,
- Yannick