|
|
 |
Re: FN-FORUM Simple Perl Script - ASP Script
date posted 21st August 2000 23:32
Hi Jon
Here's the bare bones of the code that will let you edit a text file. If
you just want the script then jump to the end of the message, as I'm going
to explain how it works. This is all ASP2, and I tested it on PWS on Win98
(I can't be arsed to try it on IIS tonight).
What we use is the FileSystemObject object, which gives us access to the
physical drives and directories on the server.
The first page we'll call reader.asp, this reads the text file that the
client will edit. To do this we create a FileSystemObject object.
We then use this to open the text file we wish to edit as a textstream. We
use the full physical path to the file thus.
This allows us read access to the text file. So we pull all of the contents
of the text file out and stuff them into a variable.
This is all done server side. What we then want to do is to deliver the
file contents to the client and give them the ability to edit them. So what
we'll do is use a form as our client/server interface.
This will create a textarea box on the client side, which will contain all
of the contents of the text file. The user can then edit the contents, add
new contents etc etc to their hearts content. When they're finished editing
it they'll hit the submit button which fires off the contents of the
textarea to our second page, writer.asp.
The first thing we want to do in our second page is get the newly edited
contents from that textarea (forgive me if I'm teaching your grandmother to
suck eggs)
Next we create a new FileSystemObject object.
We then use this to create a new text file on the server (this will
overwrite the old one)
Next we take our variable containing the newly edited textarea content, and
write it to the text file.
Finally we close our object and our work is done.
So the workflow of this is
Read Text File > Write Content to Text Area > Edit Content > Submit Form >
Read Form > Write Text File
If you're any further questions then feel free to ask. Of course I could
have totally the wrong end of the stick and all the people that really know
stuff on the list will flame me now! :)
Norman
Here's the code. The only difference to that above is that I've included
all the HTML to be written within the ASP. This means that all the HTML is
written in one visit to the response object, rather then having to mix an
ASP response.write within the HTML. A good habit to get into.
Reader.asp
Writer.asp
|
 |
|