469,271 Members | 1,191 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Getting file size

Hi,

Does anyone know how to get the size of an xml file using VB.NET? I
haven't the slightest idea where to begin.

Thanks,
Roshawn
Nov 12 '05 #1
3 9060
Import System.IO

FileStream stm = File.OpenRead(path)
int length = stm.Length
stm.Close()
"Roshawn Dawson" <ud****@bellsouth.net> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Hi,

Does anyone know how to get the size of an xml file using VB.NET? I
haven't the slightest idea where to begin.

Thanks,
Roshawn

Nov 12 '05 #2
Thanks, Chris. That helps alot!! :-)

Chris Lovett wrote:
Import System.IO

FileStream stm = File.OpenRead(path)
int length = stm.Length
stm.Close()
"Roshawn Dawson" <ud****@bellsouth.net> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Hi,

Does anyone know how to get the size of an xml file using VB.NET? I
haven't the slightest idea where to begin.

Thanks,
Roshawn


Nov 12 '05 #3
[quote=Chris Lovett]Import System.IO

FileStream stm = File.OpenRead(path)
int length = stm.Length
stm.Close()


For future generations the above code is incorrect:
stm.Length can return long so you should set length to long.

Also you you do not need to instantiate a FileStream object. You instead can:

long size = File.OpenRead(Server.MapPath(path)).Length;

Server.MapPath is because I am working in a ASP.NET enviroment and thus commonly refer to file's virtual path as the absolute path is not always apparent programmatically.
Apr 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by middletree | last post: by
17 posts views Thread by Arnold | last post: by
11 posts views Thread by KarimL | last post: by
12 posts views Thread by leonard.guillaume | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.