Solved

read txt file

Posted on 2006-07-06
6
256 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
Comment Utility
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
Comment Utility
Out of interest, which line is line 34 in your code above?
0
 
LVL 6

Expert Comment

by:Dragonlaird
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Accepted Solution

by:
Dragonlaird earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
No problem, glad I could help
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

11 Experts available now in Live!

Get 1:1 Help Now