Saturday, March 28, 2009

getFileType

Last week I showed you how to get the size of a file. This week I'm going to show you how to get the type of a file. This is useful if you want to display an icon or bit of text next to a hyperlink to indicate the file type. Some people like to use this to warn visitors when they link to a PDF file, because PDF readers can take a while to load.


ASP

  1. function getFileType(someFile)
  2.     dim fs
  3.     set fs = Server.CreateObject("Scripting.FileSystemObject")
  4.     getFileType = fs.GetExtensionName(Server.MapPath(someFile))
  5.     set fs = nothing
  6. end function

See you next week!


View ASP implementation on Snipplr

No comments: