By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,055 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

Determining File Size In Code

P: n/a

It looks like the only way to get a size of a file within dot net is to
use FileInfo and the Length property. However that only returns the
number of bytes in the file which is translating properly (I have a
file that has a size of 1 KB but has 14 bytes in it so the conversion
isn't working right). Is there some method/property out there that
will get the actual size of the file? Also, would there be a method
like this that will get this size of a file that is being written to?
(I need to write data to a file but need to track how big the file is
getting as I'm writing it.)

Oct 4 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a
>Is there some method/property out there that
>will get the actual size of the file?
You are getting the actual size of the file. The number in Windows Explorer
is just rounded up. I tried this myself, and at 1024 bytes, the file size
reads 1KB in Explorer. At 1025, it's 2. So you need to do your conversion
based on the same type of rounding.

As for reading it from a file that's being written, I think this will work
if you call the Flush() method of the StreamWriter and then do your size
Oct 4 '06 #2

P: n/a
The rounding up was kind of what I was coming around to as well as I
was posting this. Thanks for the suggestions, I will give them a try!

Oct 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.