|
-
Jan 30th, 2001, 11:14 AM
#1
Thread Starter
Hyperactive Member
How do i open a text file and print to screen with ASP..
G
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 30th, 2001, 11:48 AM
#2
Fanatic Member
Hi again
nice and easy this one
Dim FSO
Dim myfile
Dim ts
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set FSO = Server.CreateObject("scripting.FileSystemObject")
set myFile = FSO.GetFile("C:\test1.txt")
set myFile = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine & "<br>"
Loop
Hope it helps
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 30th, 2001, 12:00 PM
#3
Thread Starter
Hyperactive Member
It will thanks.... could it be any smaller?
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 30th, 2001, 12:03 PM
#4
Fanatic Member
unfortunatley not.
and also, please change this line
set myFile = f.OpenAsTextStream(ForReading, -2)
to
set ts = f.OpenAsTextStream(ForReading, -2)
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 30th, 2001, 12:11 PM
#5
Thread Starter
Hyperactive Member
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 30th, 2001, 12:12 PM
#6
Thread Starter
Hyperactive Member
this is what i have
Dim FSO
Dim myfile
Dim ts
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set FSO = Server.CreateObject("scripting.FileSystemObject")
set myFile = FSO.GetFile(App.Path & "\license.txt")
set ts = f.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine & "<br>"
Loop
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 30th, 2001, 12:33 PM
#7
Thread Starter
Hyperactive Member
set myFile = f.OpenAsTextStream(ForReading, -2)
Whats f ???
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 30th, 2001, 04:07 PM
#8
Fanatic Member
Dohh, sorry mate I screwed up again, it's been one of those day's. change it to
set ts = myFile.OpenAsTextStream(ForReading, -2)
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 05:06 AM
#9
Thread Starter
Hyperactive Member
I'd already done that.. still dont work says object requied on this line
set myFile = FSO.GetFile(App.Path & "\license.txt")
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 05:19 AM
#10
Fanatic Member
just seen what is worng. App.path is not a valid function in asp, you need to use the server variable
filepath = request.servervariables("APPL_PHYSICAL_PATH")
that returns the physical path of the current file
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 05:24 AM
#11
Thread Starter
Hyperactive Member
New stuff ehh!!
is this valid then
set myFile = FSO.GetFile(filepath & "\license.txt")
Becuase i get file not found.. it is there.?
G
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 05:27 AM
#12
Fanatic Member
take the foward slash out of license
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 05:36 AM
#13
Thread Starter
Hyperactive Member
Tried it.. still didn't work
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 05:41 AM
#14
Fanatic Member
could you do a response.write filepath & "license.txt" and post it here please.
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 05:51 AM
#15
Thread Starter
Hyperactive Member
<b>C:\Inetpub\wwwroot\license.txt</b>
There you go...
oops i may of found it... i'll let you know.. hold on a minute.. filepath is only doing C:\Inetpub\wwwroot\ and not
C:\Inetpub\wwwroot\inetcost\ .. why's that.?? thats the filepath?
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 05:53 AM
#16
Thread Starter
Hyperactive Member
Now this dont work after all that... we'll get there yet
<textarea name="license" cols="80" rows="15" wrap="VIRTUAL" READONLY >
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set FSO = Server.CreateObject("Scripting.FileSystemObject")
filepath = Request.ServerVariables("APPL_PHYSICAL_PATH")
set myFile = FSO.GetFile(filepath & "inetcost\license.txt")
set ts = myFile.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine & "<br>"
Loop
%>
</textarea>
This is everything... it fills in the <textarea> tag.
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 06:23 AM
#17
Fanatic Member
right, i thought so, i'm using the wrong server variable.
I've just looked at all of them and the one you need is PATH_TRANSLATED. unfortunatley this also includes the filename of the asp page as well so you need to play with it a bit
Code:
<%
Dim blnfound
Dim filepath
Dim filename
Dim icount
'get the full path
filepath = request.servervariables("PATH_TRANSLATED")
blnFound = True
icount = 1 'start at the beguining of the string
While blnfound = True
'find a \ in the file path
if InStr(icount,filepath,"\") >= 1 Then
'set the counter to look for another "\" after the one it has just found
icount = instr(icount,filepath,"\") + 1
else
' no more "\"
blnfound = False
End If
wend
'start at the begining and grab everything up to the last "\"
filename = Mid(filepath,1,icount - 1) & "license.txt"
a bit if a bugger, but it works
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 06:32 AM
#18
Thread Starter
Hyperactive Member
<textarea name="license" cols="80" rows="15" wrap="VIRTUAL" READONLY >
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set FSO = Server.CreateObject("Scripting.FileSystemObject")
filepath = Request.ServerVariables("APPL_PHYSICAL_PATH")
set myFile = FSO.GetFile(filepath & "inetcost\license.txt")
set ts = myFile.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine
Loop
Response.Write myText
%>
</textarea>
This works but strips out all spaces and breaks in text file
Cheers Ian
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 06:38 AM
#19
Fanatic Member
Yeah that will work. the code above is handy to have if you need the actual directory of the file
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 06:39 AM
#20
Thread Starter
Hyperactive Member
It worked! a bit long but ..
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 06:44 AM
#21
Thread Starter
Hyperactive Member
Why dont it print the line breaks and spaces in the license.txt
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Jan 31st, 2001, 06:46 AM
#22
Fanatic Member
it's only 11 lines of code. stick it in a function, then in a include file and hey presto you have your own asp app.path 
Ian
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jan 31st, 2001, 07:11 AM
#23
Thread Starter
Hyperactive Member
How can i make this:
Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine
Loop
Pickup spaces and breaks in text file?
Regards Gary
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Feb 1st, 2001, 09:32 AM
#24
Addicted Member
To a save a lot of messing around with filepaths, use this bit of code.
path = server.MapPath("../images/wierddirectory/buriedinthemiddleofnowhere")
Set SaveFile = server.CreateObject("scripting.filesystemobject")
set imagefile = savefile.CreateTextFile(path & "\" & filename)
-
Feb 1st, 2001, 09:34 AM
#25
Addicted Member
Ohh, and to pick up line breaks do this..
Replace (mytext, chr(13), "<BR>")
And just replace chr(13) with the space chr(Ive forgotten what it is) and "<BR>" with " "
-
Feb 1st, 2001, 09:41 AM
#26
Thread Starter
Hyperactive Member
Get this error when using )
Cant use parantheses when calling a sub, taking them away doe'snt read the spaces or breaks. chr(10) i think is a space.
g
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Feb 1st, 2001, 09:49 AM
#27
Addicted Member
You need to assign the result to a variable...
mytext = replace(mytext, chr(13), "<BR>")
-
Feb 1st, 2001, 10:20 AM
#28
Thread Starter
Hyperactive Member
Still wont work..
<textarea name="license" cols="80" rows="15" wrap="VIRTUAL" READONLY>
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set FSO = Server.CreateObject("Scripting.FileSystemObject")
'get the full path*****************************************
getFileAndPath = filePath
'************************************************************
set myFile = FSO.GetFile(getFileAndPath)
set ts = myFile.OpenAsTextStream(ForReading, -2)
Do While not ts.AtEndOfStream
myText = myText & ts.ReadLine
Loop
myText = replace(myText, chr(10), "s")
myText = replace(myText, chr(13), "z")
Response.Write myText
%>
</textarea>
"Life isn't about finding yourself. Life is about creating yourself."
--George Bernard Shaw
-
Feb 1st, 2001, 10:31 AM
#29
Addicted Member
I cut and pasted that code, and ran it(With a new filename) and it works fine. If theres a problem remember to give an error message, or I dunno whats wrong with it. The problem with the "no parenthases" error is normally that one of your variables is empty, so check myText actually has something in it. I realise its not going to be that, but I cant think of anything else that may be wrong with it....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|