read txt file
Posted on 2006-07-06
I have a strange problem which looks very easy but I can't find out what the problem is.
I have the following code which works fine if I read the main.txt from the default web site folder.
As soon as I move the file into another folder on the server e.g.: D:\IT\Intranet\ I get this error:
Microsoft VBScript runtime (0x800A0034)
Bad file name or number
/intranet/index.asp, line 34
Even if I create a virtual folder on the IIS it doesn't work.
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
TheFile = Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))
loc = InStrRev(TheFile,"\")
TheFile = Left(TheFile,loc)
Set f = fso.GetFolder(TheFile)
Set fc = f.Files
Set TitleFile = fso.OpenTextFile(TheFile & "D:\IT\Intranet\main.txt")
TextBuffer = TitleFile.ReadAll
Please help, if you can.