Solved

VB.Net Getting file size in MBs/KB's

Posted on 2012-12-26
2
3,142 Views
Last Modified: 2012-12-26
Hi Experts.  
Can some please explain why I keep getting the answer 13 when the actual file size is 1.3G and how I would get MB's and KB's

Dim filename As String
filename = ("C:\backup.pst")
MsgBox(filename.Length)

I've tried converting to integer and long but then I just get 0

Thanks
0
Comment
Question by:PNRT
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38721552
Because you are asking for the length of a string. "C:\backup.pst" is 13 characters in length. To get file size do:

Dim info As New System.IO.FileInfo(@"C:\backup.pst")
MsgBox(info.Length)

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38721564
P.S.

The Length property will give you the count of bytes for the file. To convert to human quantities you will have to do a bit of math:

info.Length / 1024  ' kilobytes
info.Length / 1048576 ' megabytes
info.Length / 1073741824 ' gigabytes

Open in new window

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question