Link to home
Start Free TrialLog in
Avatar of rito1
rito1

asked on

Obtaining File size in MB using System.io

Hi All

Using System.io, how can I obtain the file size in megabytes for the following file:

C:\inetpub\wwwroot\mysite\test\test.pdf

Many thanks
Rit
Avatar of Si_Hibbard
Si_Hibbard
Flag of United States of America image

Use the FileInfo class and the length attribute
Avatar of cmhunty
cmhunty

So that'd be

Dim fi as New FileInfo("C:\inetpub\wwwroot\mysite\test\test.pdf")
Dim intSize as Int32 = fi.Length
Avatar of rito1

ASKER

thanks both.

cmhunty, that is roughly what I have so far but wondered how I would then change the returning value to MB and really need to round it to 2 decimal places too.

Many thanks in advance

Rit
ASKER CERTIFIED SOLUTION
Avatar of Si_Hibbard
Si_Hibbard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry shoud be 1024 not 1000
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rito1

ASKER

Brilliant, many thanks.

Rit