Here’s a function in ASP from my code lib that I wrote quite a while ago to read the contents of a file into a variable when I was trying some custom tag parsing in a template engine of mine that I was making in ASP. 💡 The details are quite boring so you better not know them, the project was one of my un-sung part-failures but I learned quite a lot by working on that pet project. 😉
So, here’s the function.
[asp]
Private Function readMyFile(pFileName)
	SET FSO = Server.CreateObject(“Scripting.FileSystemObject”)
	IF (TRIM(pFileName)=””) THEN
		EXIT FUNCTION
	ELSE
		IF FSO.FileExists(Server.MapPath(pFileName)) THEN
			SET mFile = FSO.OpenTextFile(Server.MapPath(pFileName))
			readMyFile = mFile.ReadAll
		ELSE
			readMyFile = “File Not Found”
		END IF
	END IF
	SET mFile = NOTHING
	SET FSO = NOTHING
End Function
[/asp]
Use it well. 😀 😉