Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Out of Memory Exception while reading large file

$
0
0

Hi All,

I want to read the large XML fiile (500 MB). I am using below code... but I am facing  Out of Memory exception...

        public static byte[] Compress(XElement xml)
        {
            string tempFilePath = Path.GetTempFileName();
            using (FileStream stream = File.OpenWrite(tempFilePath))
            {
                xml.Save(stream);
                stream.Flush();
                stream.Close();
                Byte[] srcFileByte = File.ReadAllBytes(tempFilePath);
                return srcFileByte;
             }
}

Can you please let me know whats is wrong in above code? 

-Ajit


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>