Textbox editing...

K

Ketta

I know how to read a file system object and output it to the browser page.
The desired result would be to put that file into a textbox on the screen
for a user to modify and then write the file back to the file system. The
concept seems simple enough, read the text file into a variable then some
magic asp will put it into a textbox value, then somehow take that value and
write the file. I know how to write files to the system as well. I am
missing a key piece.. any ideas?

Thanks,
Ketta
 
R

Ray at

Alright, you have the file in a textbox already, so once the user submits
the file, take the request.form("thatTextbox"), create an FSO object, and
overwrite the existing file with the contents from that textbox.

Ray at home
 
K

Ketta

Well thanks for that part, that will definately help me. But I still do not
have the file in a textbox. It just outputs it to the screen. This is my
code for reading the file and putting it on the screen. I'm a total noob
with ASP btw. This is probably just annoying to have someone like me asking
for help. Now all I need is the code below to output to a textbox....
somehow.


<%
set fso = server.createobject("Scripting.FileSystemObject")
set fs = fso.openTextFile("textfile.txt",1,true)
response.write replace(replace(fs.readall,"<","<"),vbCrLf,"<br>")
fs.close: set fs = nothing: set fso = nothing
%>

Thank you
Ketta
 
R

Ray at

Ketta said:
Well thanks for that part, that will definately help me. But I still do not
have the file in a textbox. It just outputs it to the screen. This is my
code for reading the file and putting it on the screen. I'm a total noob
with ASP btw. This is probably just annoying to have someone like me asking
for help.

If I were annoyed, I wouldn't use newsgroups. :]
Now all I need is the code below to output to a textbox....
somehow.


<%
set fso = server.createobject("Scripting.FileSystemObject")
set fs = fso.openTextFile("textfile.txt",1,true)
response.write replace(replace(fs.readall,"<","<"),vbCrLf,"<br>")
fs.close: set fs = nothing: set fso = nothing
%>

You can just server.execute the contents of the file, i.e.

http://yoursite/filemod.asp?filename=file.txt :
<%
sFilename = Request.Querystring("filename")
%>

<html>
<form method="post" action="filemodp.asp">
<input name="filename" value="<%=sFilename%>" type="hidden">
<textarea name="fileContents" style="width: 500px; height: 800px;"><%
Server.Execute sFilename %></textarea>
<input type="submit">
</form>



http://yoursite/filemodp.asp :
<%
Dim sFilename, sContents
sFilename = Request.Form("filename")
sContents = Request.Form("fileContents")
If sFilename <> "" Then
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.CreateTextFile(Server.MapPath(sFilename), True)
oFile.Write sContents
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing
End If

Response.Redirect "filemod.asp?filename=" & sFilename
%>


Play around with that to see what I mean. But, what you'll want to do first
is create a file named "file.txt" throw a few characters into it, and then
load up the filemod.asp page with the ?filename=file.txt querystring. This
sample has no handling of errors for empty or non-existant files.

Ray at work
 
C

Chris Hohmann

Ketta said:
Well thanks for that part, that will definately help me. But I still do not
have the file in a textbox. It just outputs it to the screen. This is my
code for reading the file and putting it on the screen. I'm a total noob
with ASP btw. This is probably just annoying to have someone like me asking
for help. Now all I need is the code below to output to a textbox....
somehow.

Wrap the file content in textarea tags like so:

<%
set fso = server.createobject("Scripting.FileSystemObject")
set fs = fso.openTextFile("textfile.txt",1,true)
Response.Write "<textarea name='myTextArea' cols='80' rows='10'>"
Response.Write fs.readall
Response.Write "</textarea>"
fs.close: set fs = nothing: set fso = nothing
%>

HTH
-Chris Hohmann

P.S. Your question was not annoying and you don't need to apologize for
being new to ASP. Everyone was once. :) Hope to hear from you again.
 
C

Chris Hohmann

You can just server.execute the contents of the file, i.e.

http://yoursite/filemod.asp?filename=file.txt :
<%
sFilename = Request.Querystring("filename")
%>

<html>
<form method="post" action="filemodp.asp">
<input name="filename" value="<%=sFilename%>" type="hidden">
<textarea name="fileContents" style="width: 500px; height: 800px;"><%
Server.Execute sFilename %></textarea>
<input type="submit">
</form>

This introduces a significant security hole in the system since it
allows the end user to post/execute code of their choosing. I would
stick with using the FSO.

-Chris Hohmann
 
R

Ray at

That is quite true.

Ray at work

Chris Hohmann said:
This introduces a significant security hole in the system since it
allows the end user to post/execute code of their choosing. I would
stick with using the FSO.

-Chris Hohmann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top