Solved

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

Posted on 2012-12-26
2
3,338 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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