I have to read a file content Base64 string in an element of XML that is returned from an API.
My problem is this string can be very long, depending on file size.
At first, I used XmlDocument
to read XML. Now I use XmlReader
to avoid
System.OutOfMemoryException
when XML is too large.
But I when I read the string, receive a System.OutOfMemoryException
too.
The string is too long, I guess.
using (XmlReader reader = Response.ResponseXmlXmlReader)
{
bool found = false;
//Read result
while (reader.Read() && !found)
{
if(reader.NodeType == XmlNodeType.Element && reader.Name == "content")
{
//Read file content
string file_content = reader.ReadElementContentAsString();
//Write file
File.WriteAllBytes(savepath + file.name, Convert.FromBase64String(file_content));
//Set Found!
found = true;
}
}
}
How can I read file content string with XmlReader
without System.OutOfMemoryException
?