Posted by on in iDevelop | 0 comments

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.

  1. Private Function readMyFile(pFileName)
  2.     SET FSO = Server.CreateObject("Scripting.FileSystemObject")
  3.     IF (TRIM(pFileName)="") THEN
  4.         EXIT FUNCTION
  5.     ELSE
  6.         IF FSO.FileExists(Server.MapPath(pFileName)) THEN
  7.             SET mFile = FSO.OpenTextFile(Server.MapPath(pFileName))
  8.             readMyFile = mFile.ReadAll
  9.         ELSE
  10.             readMyFile = "File Not Found"
  11.         END IF
  12.     END IF
  13.     SET mFile = NOTHING
  14.     SET FSO = NOTHING
  15. End Function

Use it well. 😀 😉