views:

141

answers:

2

I am using the following code to write to a compressed file that I create new everytime.

using (FileStream fs = File.Open(sortOrderFileName, FileMode.Create,FileAccess.Write, FileShare.ReadWrite))
using (System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress))
using (StreamWriter sw = new StreamWriter(gzip))
{
     // use the streamwriter sw to write to the stream
}

However, when I run this, I am getting an IOException with the message "Out of disk space". However, there is 19GB of space available on the drive on which I am writing the file.

According to the docs for GZipStream, it cannot be used to write a file greater than 4GB. However, the file written till now is only 250MB in size.

Here is the exception:

Type: System.IO.IOException Exception Msg: There is not enough space on the disk.

Inner Exception: StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count) at System.IO.FileStream.FlushWrite(Boolean calledFromFinalizer) at System.IO.FileStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Compression.DeflateStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Compression.GZipStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.StreamWriter.Dispose(Boolean disposing) at System.IO.StreamWriter.Close()

Also, this is not a network file.

Any ideas what I am doing wrong here?

A: 

This message can appear if the disk quota assigned to the user has been reached.

An administrator can set the per-user quota by right-clicking on the disk in My Computer, choosing Properties, and using the Quota tab.

Verify that quotas are disabled or that the user your application is running as has sufficient quota.

binarycoder
Yes, as I mentioned, the machine has a lot of disk space available when this happens. Also, the user quota is not exhausted.
feroze
A: 

Change the FileShare mode to exclusive to see if that makes a difference, I don't understand why the FileShare is set to Read/Write? Any explanation for that, when compressing, the file should be exclusive for the gzip to work properly...

Hope this helps, Best regards, Tom.

tommieb75