Solved

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

Posted on 2012-12-26
2
3,412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

696 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