Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

read txt file

Posted on 2006-07-06
6
Medium Priority
?
314 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Accepted Solution

by:
Dragonlaird earned 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

886 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