Solved

read txt file

Posted on 2006-07-06
6
269 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i convert a Generic list to DataTable in c# 3 772
SQL Filter Question 8 79
Use a variable for Class Name in Classic ASP 4 46
ASP Button to clear text 4 44
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now