pulpfiction Posted May 16, 2006 Share Posted May 16, 2006 Hi guys,How can we get the size of a particular [PDF] file . I'm using ASP.NET/VB. Thanks. Link to comment Share on other sites More sharing options...
aspnetguy Posted May 16, 2006 Share Posted May 16, 2006 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 More sharing options...
pulpfiction Posted May 17, 2006 Author Share Posted May 17, 2006 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 More sharing options...
aspnetguy Posted May 17, 2006 Share Posted May 17, 2006 Do you mean you need to check files on remote servers not just the local web server? Link to comment Share on other sites More sharing options...
pulpfiction Posted May 17, 2006 Author Share Posted May 17, 2006 yeah, i mean to check from remote server.. Link to comment Share on other sites More sharing options...
aspnetguy Posted May 17, 2006 Share Posted May 17, 2006 try thishttp://rtfm.atrax.co.uk/infinitemonkeys/ar...sp.net/990h.asp Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now