Click to See Complete Forum and Search --> : Reading from file into text box, then writing back to the file.


kelemvor
12-18-2003, 08:13 PM
Greetings,

I don't know much ASP at all so I'm hoping someone can offer me a simple script to do this.

I want to have a file on my server called something like edit.html. I want to have a page that will simply contain one TextArea and one Submit button.

When the page is loaded I want it to read whatever is in the html file into the textarea window. Then I want to user to be able to change what's in the box. Then I want a button they can click that will write whatever is in the box at the time to the html file and overwrite anything that might have been in it.

I don't think this would be very difficult for someone who knows ASP, but that's not me. Javascript I can do, but ASP I can't. heh heh.

Can anyone help me with this?

Thanks!!

PeOfEo
12-18-2003, 08:59 PM
why edit an html file? Why not just read and write into a data base and then display it in a .asp file for users to see.

kelemvor
12-18-2003, 09:04 PM
Well I want to use this with an Include statement to display it in a certain place on a certain webpage. Basically the President of our Association wants a way to add important text to a spot on the website on the fly in case urgent issues come up before I can update the site at night.

I'm open to any ways of doing this....

--Mike

PeOfEo
12-18-2003, 10:17 PM
Yes, use a data base and get the content from it. You can still position it anywhere. You can still use an include. Data bases are faster to write then text files and its more accuarate, he can do it without knowing html. If you waned to edit and html doc it would be like editiing a text file which is a pain in the butt. Just using an xml or access data base for small things would probably better suit your needs. http://www.clanknights.vze.com is my site, I am redoing the layout now, but the new stuff isnt up. That news column is data bound but you can put data anwhere you want, in span's divs anything, just give the div an id and tell it to runat the server and put the data in it. It isnt hard at all.

kelemvor
12-18-2003, 11:24 PM
Well then I guess this would turn out to be a How do I do an Include and pull a field from a database? As well as how do I Read the field into a text box and then rewrite it.

Like I said, I know basically no ASP. I can take some scripts and tweak them, but can't write anything from scratch.

Thanks.

Gunner
12-19-2003, 12:38 AM
I have something that might work!

Just unzip and put in your root directory
Then navigate to: DisplyFile.asp

Let me know if it works for you.

PeOfEo
12-19-2003, 01:00 AM
Originally posted by kelemvor
Well then I guess this would turn out to be a How do I do an Include and pull a field from a database? As well as how do I Read the field into a text box and then rewrite it.

Like I said, I know basically no ASP. I can take some scripts and tweak them, but can't write anything from scratch.

Thanks. Why do you even need an include? Why not just have you index be an asp.net page and get the content from the data base. You do not do an include you use an sql statement. I suggest you learn asp istead of just modding scripts. You should actually learn asp.net in my opinion since it is newer and outperforms asp classic in almost every way. But you really should buy a book and try to learn it so you can make stuff scalable and be able to make new things that accomplish exactly what you want. I can hook you up with some asp.net scripts that will do what you want if the one above does not accomplish what you want to but, I do not want to write them if you do not want to learn ;)

kelemvor
12-19-2003, 08:06 AM
We already have a complete website that is up and running and works just fine. We simply want to add one little section on the front page where someone in the office could go to a specific web page, fill out a form/text box/whatever, and have that information then appear on the front page.

I'm not going to go buy lots of books and learn an entire scripting/programming language to simply accomplish one small task.

I saw this tutorial: Link (http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject_opentextfile.html) which has some helpful information but I'd still need to know how to put the read in info into a text box and then how to pull it back out of the text box and put it back in the file.

Any help with this would be great.

Gunner
12-19-2003, 09:10 AM
Hi Kelemvor,

The script in my first post does just that...it uses the FileSystemObject and you can link to it...you can even mod it very easy to fit your site.

PeOfEo
12-19-2003, 02:50 PM
Originally posted by kelemvor
We already have a complete website that is up and running and works just fine. We simply want to add one little section on the front page where someone in the office could go to a specific web page, fill out a form/text box/whatever, and have that information then appear on the front page.

I'm not going to go buy lots of books and learn an entire scripting/programming language to simply accomplish one small task.

I saw this tutorial: Link (http://www.devguru.com/Technologies/vbscript/quickref/filesystemobject_opentextfile.html) which has some helpful information but I'd still need to know how to put the read in info into a text box and then how to pull it back out of the text box and put it back in the file.

Any help with this would be great. But you still do not need an include to do this. I reccomend against and include because you would be having to include the script too or using a code behind.

kelemvor
12-19-2003, 06:55 PM
Originally posted by Gunner
Hi Kelemvor,

The script in my first post does just that...it uses the FileSystemObject and you can link to it...you can even mod it very easy to fit your site.

I must have missed that the first time. I downloaded the script and put the 3 files in my root. The Disply and edit file work fine, but I get a Page cannot be displayed when I clicked on the Modify button and when I try to access the page manually. Not sure why.... I even renamed the file to x.asp and still get the Page Cannot be Displayed error when typing in the direct address to the file....

Gunner
12-19-2003, 07:44 PM
Sorry about that! I had it set to go to index.asp when done.

At the bottom of WriteToFile.asp change

Response.Redirect "/index.asp"

to reflect the page you want to go to when done

for example "/DisplyFile.asp"

kelemvor
12-19-2003, 07:53 PM
I actually saw that on there and tried changing it with no affect. When the error comes up it's still on the WriteToFile page and doesn't look like it's looking for any other page.

Feel free to view it at www.gmar.ws

www.gmar.ws/DisplyFile.asp works fine
www.gmar.ws/edit.html works fine
www.gmar.ws/WriteToFile.asp gives a 500 error. Page cannot be displayed. I even copied the file to www.gmar.ws/x.asp and it still doesn't work.

No idea why.

Gunner
12-19-2003, 08:00 PM
That is a permissions problem:

Microsoft VBScript runtime error '800a0046'

Permission denied

/WriteToFile.asp, line 12

You'll have to contact your host about it.

PeOfEo
12-20-2003, 12:33 AM
Or you could just write it into a data base instead of appending a text file :rolleyes:. Outputting html from a data base via a page that uses a select sql statement is very easy too... Does your server support asp.net? Look at www.clanknights.vze.com that is a poor example but look at the news column. You can do things like that with a data base where you populate a data grid. Or you can make something that only puts text in one little span, and everything inbetween.

Gunner
12-25-2003, 03:46 AM
kelemvor

Here is the modified script.

For those that are asking

the modified script works with htmlArea v2.03 which takes any textarea box and makes it a WYSIWYG editor

It's free and you can get it here:htmlArea v2.03 (http://www.interactivetools.com/products/htmlarea/)

kelemvor
12-25-2003, 08:50 AM
That is Sweet! Thanks a TON for doing that. Looks good upon my initial viewing. I'll play with it a bit and make sure I can't break it. heh.

Merry Christmas!

Gunner
12-25-2003, 01:10 PM
No problem!

Glad I could help.

One thing I noticed is that it double spaces the lines of text, I can fix that if you dont want double spacing...just let me know

Merry Christmas to you too!

IceMetalPunk
12-26-2003, 01:51 PM
I have a good idea, but it uses ActiveX instead of ASP. You could save the file on the user's computer in your own folder, open it and read it, then let them change it. Something like this should work:

<script>
function ReadFile() {
fso=new ActiveXObject("Scripting.FileSystemObject");
if (!fso.folderExists("C:\\My R/RW Files")) { fso.createFolder("C:\\My R/RW Files"); fso.createTextFile("C:\\My R/RWFiles\\My File.html"); }
if (!fso.fileExists("C:\\My R/RW Files\\My File.html")) { fso.createTextFile("C:\\My R/RW Files\\My File.html"); }
editableFile=fso.OpenTextFile("C:\\My R/RW Files\\My File.html");
document.fileform.filearea.value=editableFile.ReadAll();
}
function SaveFile() {
fso=new ActiveXObject("Scripting.FileSystemObject");
if (!fso.folderExists("C:\\My R/RW Files")) { fso.createFolder("C:\\My R/RW Files"); fso.createTextFile("C:\\My R/RWFiles\\My File.html"); }
if (!fso.fileExists("C:\\My R/RW Files\\My File.html")) { fso.createTextFile("C:\\My R/RW Files\\My File.html"); }
editableFile=fso.OpenTextFile("C:\\My R/RW Files\\My File.html");
fso.Write(document.fileform.filearea.value);
}
</script><body onLoad="ReadFile()"><form name="fileform"><textarea name="filearea" rows=10 cols=50></textarea><P><input type="button" onClick="SaveFile()">

The only problem is this will only work with IE.
Good Luck :) -
IceMetalPunk