Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

read txt file

 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:
Error Type:
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.

  • 5
1 Solution
First suggestion, ensure the folder security settings do not stop the IUSR_Machinename user account from having at least read-only access - Otherwise, the web service cannot see the file/folder.

Just right-click the folder and view the Properties of the folder, then click the Security tab. If IUSR_xxx isn't listed as a user add it and grant the account Read access.
Out of interest, which line is line 34 in your code above?
Apart from the stuff above... I think the cause of your problem will be the following line...

Set TitleFile = fso.OpenTextFile(TheFile & "D:\IT\Intranet\main.txt")

The reason I suspect this, if your variable 'TheFile' contains ANY text, the resulting string inside the brackets will make no sense to fso... For example,

Supposing TheFile = "ABC123"

Then you are trying to open a file called:


Which of course doesn't exist because there isn't a drive called ABC123D:

Hope this helps...
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

So replace your current line...

Set TitleFile = fso.OpenTextFile(TheFile & "D:\IT\Intranet\main.txt")


Set TitleFile = fso.OpenTextFile("D:\IT\Intranet\main.txt")

And assuming the file 'D:\IT\Intranet\main.txt' actually exists and the web service has read permissions to access the file, your problem should be solved.
tradexinsuranceAuthor Commented:
Thx m8 I changed that line and it works now.
I thought that there might be a problem with that
that variable but I'm not so good at ASP yet.:)
Thx again!
No problem, glad I could help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now