Return to Snippet

Revision: 5567
at March 16, 2008 20:04 by neal_grosskopf


Initial Code
function GetFileSizeType(WhatFile)

	set fs=Server.CreateObject("Scripting.FileSystemObject")
	file = Server.MapPath(WhatFile) 
	set f = fs.GetFile(file)
	intSizeK = Int((f.Size/1024) + .5)
	if intSizeK = 0 then intSizeK = 1
	
	GetFileSizeType = "("&UCase(fs.GetExtensionName(file))&", "&intSizeK&"K)"
	
	set f=nothing
	set fs=nothing

end function

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

Initial Description
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.

Initial Title
Get File Size And Type Using ASP

Initial Tags
file, ASP

Initial Language
ASP