Jump to content

Size of a file


pulpfiction

Recommended Posts

this piece of code uses a GIF but a PDF works the same.

Dim MyFile As String = "~/photos/mymug.gif"Dim finfo As FileInfo = New FileInfo(Server.MapPath(MyFile))Dim FileInBytes As Long = finfo.LengthDim FileInKB As Long = finfo.Length / 1024Response.Write("File Size: " + FileInBytes.ToString + " bytes (" + FileInKB.ToString + " KB)")

Link to comment
Share on other sites

Thank you, this works great when the file is the wwwroot or when we give a Virtual Path.Can we make it work for any path I give like, \\servername\foldername\filename.This is how its done now. but we need to search all the files, takes some time.[fname-- name of the file whose size we need to find.]Dim di As New DirectoryInfo("\\ServerName\FolderName") Dim fiArr As FileInfo() = di.GetFiles() Dim f As FileInfo For Each f In fiArr If f.Name = fname Then Dim Size As Integer = f.Length / 1024 Return Size Else Return 0 End If Response.Write("<br>") Response.Write(f.Name) Response.Write(f.Length)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...