I have an app which I use for downloads. I've noticed that if I let it create the placeholder file, then pause it, it still shows the placeholder file size as the size that it will be, not the size that it is. And, looking at the free space on my hard drive, I can see it really is taking up that much space. That got me curious as to how they did that; I've been trying to figure out how to set the file size. I've found lots of information on how to get the file size, but none on how to set it. Nothing I've tried has worked. Curious if anyone knows if this can be done in C#?
You can use FileStream.SetLength
:
If the given value is less than the current length of the stream, the stream is truncated. In this scenario, if the current position is greater than the new length, the current position is moved to the last byte of the stream. If the given value is larger than the current length of the stream, the stream is expanded, and the current position remains the same. If the stream is expanded, the contents of the stream between the old and the new length are undefined.
See more on this question at Stackoverflow