<%
' common functions and variables are kept in here
'
'____________ Common functions __________________
' simple debug function
Function dump(strString)
Response.Write("Debug : " & strString & "")
End Function
' function to get true or false boolean values passed from a string
function getTrueFalse(strBoolean)
output=false
if ucase(trim(strBoolean)) = "TRUE" then output= true
getTrueFalse= output
end function
%>
<!-- #INCLUDE file="global.asp" -->
<%
strPathInfo = ("mytextfile.txt") ' root path to text file
strPhysicalPath = Server.MapPath(strPathInfo) ' full file path to text file
if getTrueFalse(request("callback")) then ' form submitted change file
theNewFile = Request.form("theNewFile")
fName = Server.MapPath(strPathInfo)
Set objFSO = CreateObject("Scripting.FileSystemObject") ' new filesystemobject
Set objText = objFSO.CreateTextFile(fName, true) ' create new text file with the same name
objText.Write(theNewFile) 'write contents of textarea to new file
objText.Close ' done
updatetext = "File has been saved!<br><br>"
updatetext = updatetext &"<a href="""& request.ServerVariables("SCRIPT_NAME")&""">click here to edit again</a>"
else
' load the file
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
'create filesystemobject (FSO)
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFile = objFSO.GetFile(strPhysicalPath)
textFile = "" ' this will hold the contents of the text file
'open file with FSO
set objFileTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault)
Do While objFileTextStream.AtEndOfStream <> True
strFileLine = objFileTextStream.Readline
strLine = Server.HTMLEncode(strFileLine)
strLine = Replace(strLine,CHR(9)," ")
textFile = textFile & strLine & vbCrLf
Loop
objFileTextStream.Close
end if
%>
<!-- #INCLUDE file="global.asp" -->
<CENTER>
<%
if updatetext <> "" then
response.write updatetext
else ' write form
%>
<B>EDIT PAGE</B><BR>
You can edit the text on the page below.<BR>
You can type HTML functions, such as:
BR>
<form action="<%=request.ServerVariables("/asp/editText/Copy%20of%20editText/SCRIPT_NAME")%>" method="post">
<input type="hidden" name="callback" value="true">
<textarea name="theNewFile" cols="70" rows="20" class="field"><%=textFile%></textarea>
<BR>
<input name="Submit" type="submit" class="button" value="Save & Update">
</form>
<%
end if
%>
</CENTER>