Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a text file from a virtual directory

Status
Not open for further replies.

tyant

Programmer
Jun 1, 2001
68
AU
<select name=&quot;menu1&quot; style=&quot;font-family : serif; font-size : xx-small&quot; onChange=&quot;MM_jumpMenu('parent.frames[\'PTContents\']',this,0)&quot;>
<option selected>International Past Stories</option>
<%
Dim fileObject2, textFile2

' Instantiate a FileSystemObject
Set fileObject2 = Server.CreateObject( _
&quot;Scripting.FileSystemObject&quot; )

' Newsletter path must be modified to reflect
' the file structure of the server.
newsletter = &quot;http:\\tt\pearse-trust.ie\newsletters\&quot; & &quot;news.txt&quot;

' Check if the file exists. If not, create it.
If fileObject2.FileExists( newsletter ) = True Then

' Newsletter must be open for reading.
' Open the Newsletter &quot;1&quot; is for reading.
Set textFile2 = fileObject2.OpenTextFile( newsletter, 1 )

' Read the entries from the file and write them to
' the client.
Call Response.Write( textFile2.ReadAll() )
Call textFile2.Close()
End If
%>
</select>
 
hmmmm....

Pretty.

What's it doing or not doing??? What error message(s) are you receiving?

I question your .readAll() method for writing, unless of course, you only have one line in the text file -- otherwise, what are you expecting to be written, and what is actually being written?

You also have failed to response.write any <option> tags to correctly form your select box... take a look at the code this produces, and I think your errors should be pretty apparent.

If they aren't, then post back what errors you are getting with a better description of what your text file looks like and what you are expecting to get out of this code, and maybe we can help you out.

:)
Paul Prewett
penny.gif
penny.gif
 
The only problem with my code is the line :

newsletter = &quot;http:\\tt\pearse-trust.ie\newsletters\&quot; & &quot;news.txt&quot;

I can get it working if I put in D:\file stucture

If I put in a virtual directory, I can't seem to get it working

 
Changing the back slash to a forward slash did not work

I CHANGED THIS LINE:
newsletter = &quot;http:\\tt\pearse-trust.ie\newsletters\&quot; & &quot;news.txt&quot;

TO THIS LINE:
newsletter = &quot; & &quot;news.txt&quot;
 
Double and triple check your virtual directory name --

Can you get the file by typing what you have shown here into the browser address bar?

If not, then it's the wrong address, and without being able to see your file structure and your virtual directory structure that you have set up, I'm afraid that no one here is going to be able to give you the magic pill.

Start playing around with different addresses in the address bar of your browser -- and I'll bet you stumble upon the right one.

If the problem persists, check with your network administrator to resolve the issue.

(Sorry, I just always wanted to say that) ;-)

let us know how it works out -
Paul Prewett
penny.gif
penny.gif
 
The only error is that the text is not populating the dropdown menu.
If the Directory path is on the hard drive or even on a network drive it will work.
But if I want to upload the file to work over the internet I need to change it to a virtual Directory.

Does anyone have any ideas.
 
Try Server.MapPath(virtualPath)

Hope this helps
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Your problem stems from the fact that you cannot use virtual directories with the FSO. However there is a get-around.

Are the newsletters kept in the same directory relative to where your asp is kept? For example if your asp is kept in and your newsletters are kept in /newsletters/ then you can use the following code to find the physical directory location on your server...

<%
Path = Server.MapPath(&quot;yourasp.asp&quot;)
Path = Replace(Path,&quot;yourasp.asp&quot;,&quot;&quot;)
Path = Path & &quot;newsletters\&quot;
%>

This will return something like...

D:\Inetpub\pearsetrust\newsletters

Which can be used by the FSO.

Hope this Helps

G
-GTM Solutions, Home of USITE-
-=
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top