IOException reading a large file from a UNC path into a byte array using .NET

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2008-12-22T11:58:48Z Indexed on 2010/03/19 19:21 UTC
Read the original article Hit count: 770

Filed under:
|
|
|
|

I am using the following code to attempt to read a large file (280Mb) into a byte array from a UNC path

public void ReadWholeArray(string fileName, byte[] data)
{
    int offset = 0;
    int remaining = data.Length;

    log.Debug("ReadWholeArray");

    FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

    while (remaining > 0)
    {
        int read = stream.Read(data, offset, remaining);
        if (read <= 0)
            throw new EndOfStreamException
                (String.Format("End of stream reached with {0} bytes left to read", remaining));
        remaining -= read;
        offset += read;
    }
}

This is blowing up with the following error.

System.IO.IOException: Insufficient system resources exist to complete the requested 

If I run this using a local path it works fine, in my test case the UNC path is actually pointing to the local box.

Any thoughts what is going on here ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about unc