Home Dashboard Directory Help

System.IO.File.WriteAllBytes() fails on large byte arrays by bes7252


Status: 

Closed
 as Fixed Help for as Fixed


0
0
Sign in
to vote
Type: Bug
ID: 486256
Opened: 8/28/2009 9:06:29 AM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

System.File.IO.WriteAllBytes() fails when writing a large byte array to a network drive. Original file is about 80 MB. Small files work ok. Not sure at what size they start to fail.
I've tried writing to UNC paths on 2003, 2008 and Samba. Also tried a mapped drive (e.g F:\temp\File.pdf). All fail. There are no quotas in place and permissions are okay.

System.IO.File.Copy() and System.IO.File.Move() both work on the same file without error.
Details
Sign in to post a comment.
Posted by bes7252 on 10/5/2009 at 2:38 PM
Josh,

The status of this ticket just changed to fixed. Updating the documentation doesn't really fix the problem...I still cannot write a 66MB file to a network drive.

Will the underlying Win32 library ever be modified? How about the x64 library?

Brian
Posted by Microsoft on 9/17/2009 at 1:29 PM
Hello bes7252,
Sorry for the issue with WriteAllBytes() throwing IOException when writing large files (64MB+) to network paths. The underlying Win32 WriteFile API limits network write operations to 65,535 bytes per write. In order to write large files over the network, the writes will have to be done in multiple chunks, each under 64MB.

I will make sure the System.IO documentation is updated on http://msdn.microsoft.com/ to reflect this size limitation when working with network paths.

Thank you,
Josh Free
Base Class Library Development
Posted by bes7252 on 8/31/2009 at 6:15 AM
Will the status of this ticket be updated if it's fixed?
Posted by Microsoft on 8/31/2009 at 12:20 AM
Thanks for your feedback. We are routing this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Sign in to post a workaround.
Posted by bes7252 on 8/28/2009 at 9:28 AM
Write the file to a local disk, then use System.IO.File.Move() to move the file to the UNC path.

Something like this:
string path = "\\server\share\myfile.pdf";
string tempPath = Path.GetTempFileName() + "." + Path.GetExtension(path);
File.WriteAllBytes(tempPath, file);
File.Move(tempPath, path);