ASP.NET / VB.NET: Get File Size
by Steve Hernandez on Jul.11, 2008, under Technology
If you want to get the size of a file using ASP.NET (VB), here’s how. I used this to check if the file is big enough. If it’s too small (in my application), an error existed and the user was told to contact the Administrator.
Dim fileName As String = "myFile.jpg" Dim myFileInfo As New FileInfo(Server.MapPath(fileName)) Dim fileSizeBytes As UInt32 = myFileInfo.Length Response.Write("File: " & fileName & "<br>Bytes (B): " & fileSizeBytes & _ "<br>Kilo Bytes (KB): " & fileSizeBytes / 1024 & "<br>Mega Bytes (MB): " & _ fileSizeBytes / (1024 ^ 2) & "<br>Giga Bytes (GB): " & _ fileSizeBytes / (1024 ^ 3))
Note that this only works for files that already exist ‘locally’, not those that are in ‘transport’. Meaning, you can use this for files sitting on the local server, over the network, etc, but you cannot for files pre- or during uploading, only after they’ve been uploaded and saved to the server.
 I hope this saves you some time… or at least a lengthy search on Google.
2 Trackbacks / Pingbacks for this entry
-
ASP NET VB NET Get File Size SteveOH | fix my credit
June 17th, 2009 on 7:17 AM[...] ASP NET VB NET Get File Size SteveOH Posted by root 1 hour 10 minutes ago (http://www.steve-oh.com) If you want to get the size of a file using asp net vb here how drop a comment on a post or contact us so we can take care of it powered by the tech guy ttg grafx wordpress discuss bury news asp net vb net get file size Discuss | Bury | News | ASP NET VB NET Get File Size SteveOH [...]
June 9th, 2009 on 2:56 AM
[...] ASP NET VB NET Get File Size SteveOH Posted by root 8 minutes ago (http://www.steve-oh.com) Still not finding what you 39 re looking for drop a comment on a post or contact us so we can take care of it powered by the tech guy ttg grafx wordpress Discuss | Bury | News | ASP NET VB NET Get File Size SteveOH [...]