Posted By

neal_grosskopf on 03/16/08


Tagged

file system ASP


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

neal_grosskopf
gafsveno
stefo
wizard04
nelda751


Get File Size And Type Using ASP


 / Published in: ASP
 

URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=6

Often times it is nice to add some text after a link on your website to let your users know whether the link goes to a PDF and how large that PDF file is. I've found that manually doing this works but after awhile when that PDF file get updated, the file size next to it is incorrect. It is even possible that the link is no longer a PDF but somebody forgot update the text.

An easy solution to these problems is to create a function within ASP that spits out the file type and the file size after the link to let your users know using asp how large a file is and what the file type is.

  1. function GetFileSizeType(WhatFile)
  2.  
  3. set fs=Server.CreateObject("Scripting.FileSystemObject")
  4. file = Server.MapPath(WhatFile)
  5. set f = fs.GetFile(file)
  6. intSizeK = Int((f.Size/1024) + .5)
  7. if intSizeK = 0 then intSizeK = 1
  8.  
  9. GetFileSizeType = "("&UCase(fs.GetExtensionName(file))&", "&intSizeK&"K)"
  10.  
  11. set f=nothing
  12. set fs=nothing
  13.  
  14. end function

Report this snippet  

You need to login to post a comment.