Click to See Complete Forum and Search --> : How to show file names and open test file in Notepad


davidxz
09-09-2003, 11:11 AM
I am developing an ASP application, and my client requires a page that deiplays a list of all file names, - they are text files in a folder on the server. I also need to let the user open the file in Notepad on client PC. Is this possible to do? What kind of functions in ASP I should use?

Thanks a lot for help!
David

CrazyGaz
09-09-2003, 12:05 PM
<%
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("FOLDER")

for each x in fo.files
if right(x.name,3) = "txt" then
response.write x.name
end if
next
set fo=nothing
set fs=nothing
%>

This will display all the files in a folder.

If you do something like <a href="readone.asp?name=x.name"> to link it to an individual file then you can read it like this.

<&
name=request.querystring("name")

Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile("FOLDER"&name, 1)
%>
<textarea name="message">
<%
do while f.AtEndOfStream = false
Response.Write(f.ReadLine)
Response.Write("<br>")
loop
f.close
set f=nothing
Set fs=Nothing
%>
</textarea>

this will display the text in a text box that the user can edit.

then when the user submits make sure it goes to. edit.asp?name=NAMEOFFILE

<%
name=request.querystring("name")
msg = Request.form("message")
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.CreateTextFile("FOLDER/"&name, True)
f.WriteLine (msg)
f.Close
set f=nothing
set fs=nothing
%>

You'll have to make some edits but that is the basics.

Cheers, Gaz.