Wednesday, May 29, 2013

System.IO.File.WriteAllBytes doesn't work well with large files over a network.

While moving files from one server to another, I would get an "Insufficient System Resources" message when the file was big (around 30 MB).  Turns out, WriteAllBytes works pretty well if you are moving the file around locally, but if you are writing the file to a network share, it can't handle it.  Fortunately, the following code will work:
Using MyStream As New FileStream( _
        FilePath, FileMode.Create, FileAccess.ReadWrite)
    MyStream.Write(Data, 0, Data.Length)
End Using
In this example, I am writing a byte array (represented by "Data") to a file specified by the "FilePath".

No comments:

Post a Comment