After a few hours of wondering why a FileStream read was failing on a parse I found that the length I was getting wasn't the length to expect. On right-click of an image file in Windows Explorer you can see 'Size' and 'Size on disk:'
The value I need to get from my C# application is the 'Size on disk:' - I have done a dozen tests and sure enough this is the crux of my problem -- so how do I get the 'Size on disk:' from .NET
Thanx,

Getting a File's size on disk
N30
Given the OS can report this proprtyle fairly easy I am a little surprised it is made so impossible from .NET or even the Win API.
ulven
FileStream.Read will only return as many bytes as there are available. It's return value will be 0 when you have reached the end of the stream.
Frankiee
Roland Hasenohrl
When working with a StreamReader you can get the actual size of the file (what you want) through the BaseStream.Length property. For IStream classes it is simply the Length property. For an arbitrary file you can use FileInfo.Length. These return the actual file size and not the size of the file on disk.
If you want the size of the file on disk when compressed or sparse then you have to use Platform/Invoke to call GetCompressedFileSize as I don't believe .NET exposes this method directly. Furthermore this doesn't give you the actual size on disk if it isn't compressed. For that I believe you'd have to determine how many clusters it takes up and multiply that by the cluster size. I don't believe there is any direct way in Windows to do that but WMI might provide a way. Nevertheless this is not what you'd want to use as it'll also contain unused bytes of data.
Michael Taylor - 11/20/05
Bill Rubin
This has no bearing on this discussion directly I think but might be of interest anyway.