Sending big file by webservice and OOM exception

Posted by phenevo on Stack Overflow See other posts from Stack Overflow or by phenevo
Published on 2010-05-21T13:29:27Z Indexed on 2010/05/21 15:30 UTC
Read the original article Hit count: 261

Hi,

I have webservice, with method:

[WebMethod]
public byte[] GetFile(string FName)
{
    System.IO.FileStream fs1 = null;
                fs1 = System.IO.File.Open(FName, FileMode.Open, FileAccess.Read);
    byte[] b1 = new byte[fs1.Length];
    fs1.Read(b1, 0, (int)fs1.Length);
    fs1.Close();
    return b1; 
}

and it works with small file like 1mb, but when it comes to photoshop's file (about 1,5gb) I get:

System.OutOfMemoryException

on this line:

Byte[] img = new Byte[fs.Length];

The idea is I have winforms application which get this file and saving it on local disc.

© Stack Overflow or respective owner

Related posts about c#

Related posts about webservice