Solved

read txt file

Posted on 2006-07-06
6
277 Views
Last Modified: 2012-08-14
Hello,
 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
TitleFile.Close
%>
<%response.Write(TextBuffer)%>

Please help, if you can.

Cheers,
Laszlo
0
Comment
Question by:tradexinsurance
  • 5
6 Comments
 
LVL 6

Expert Comment

by:Dragonlaird
ID: 17050636
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.
0
 
LVL 6

Expert Comment

by:Dragonlaird
ID: 17050650
Out of interest, which line is line 34 in your code above?
0
 
LVL 6

Expert Comment

by:Dragonlaird
ID: 17050687
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:

ABC123D:\IT\Intranet\main.txt

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

Hope this helps...
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 6

Accepted Solution

by:
Dragonlaird earned 50 total points
ID: 17050699
So replace your current line...

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

With...

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.
0
 

Author Comment

by:tradexinsurance
ID: 17050875
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!
0
 
LVL 6

Expert Comment

by:Dragonlaird
ID: 17050966
No problem, glad I could help
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question