//flex table opened by JP

Click to See Complete Forum and Search --> : Editing server files...


cusimar9
05-17-2005, 02:07 PM
Has anyone had experience with editing files stored on a server?

I've looked into it a few times but can't seem to get it to work.

Id really like a simple page that loads the contents of a text file into a box and allows you to edit it and save the changes.

For when a database is overkill...

kpm547
05-17-2005, 04:23 PM
you can do it with ASP and the textstream object.

Here is a link to w3schools that talks about this:

http://www.w3schools.com/asp/asp_ref_textstream.asp

Read the info from the textfile into the text box. Then upon the changes made, write the entire text box back to the text file, overwriting everything. I've done it before in a counter script that I wrote. Unfortunately I don't have the script here or I would send the portion to you.

cusimar9
05-17-2005, 05:51 PM
That's what I was having problems with before

They use local addresses in the example, but obviously I'm doing it on a server

set f=fs.CreateTextFile("c:\test.txt",true)

Can I just put the name of the file?

kpm547
05-17-2005, 06:04 PM
Here's the code that I used to open the text file.

'Create a File System Object variable
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")

'Initialise a File Object with the path and name of text file to open
Set filObject = fsoObject.GetFile(Server.MapPath("asp/hit_count.txt"))

'Open the visitor counter text file
Set tsObject = filObject.OpenAsTextStream

cusimar9
05-18-2005, 03:05 AM
Ah... we're using windows servers which don't have PHP :(

kpm547
05-18-2005, 12:09 PM
This code is ASP.

cusimar9
05-18-2005, 12:35 PM
I've managed to write the code to READ the file, but when I try and create the file I get an error "Permission Denied"

I've emailed my hosts to see if my folder has write permission... I presume that would be the problem?

<html>
<body>
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")

Set f=fs.CreateTextFile(Server.MapPath("testfile.txt"), 1)
f.WriteLine("Hello World!")
f.Close

Set f=Nothing
Set fs=Nothing
%>
</body>
</html>

kpm547
05-18-2005, 01:07 PM
This is the entire script for the reading and writing portion of my counter script.

I don't exactly remember how this works, as I wrote it a couple of years ago.

It seems as though I created a new file with the same name and then wrote the data to it. But, I needed to overwrite everything in the file.


'Create a File System Object variable
Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")

'Initialise a File Object with the path and name of text file to open
Set filObject = fsoObject.GetFile(Server.MapPath("asp/hit_count.txt"))

'Open the visitor counter text file
Set tsObject = filObject.OpenAsTextStream

'Read in the visitor number from the visitor counter file
lngVisitorNumber = CLng(tsObject.ReadAll)

'Increment the visitor counter number by 1
lngVisitorNumber = lngVisitorNumber + 1

'Create a new visitor counter text file over writing the previous one
Set tsObject = fsoObject.CreateTextFile(Server.MapPath("asp/hit_count.txt"))

'Write the new visitor number to the text file
tsObject.Write CStr(lngVisitorNumber)

'Reset server objects
Set fsoObject = Nothing
Set tsObject = Nothing
Set filObject = Nothing


And yes, your directory will have to have read and write permissions.