% 'This ASP script originally lived at http://evolvedcode.net/ for the 'original version of this script and a wide variety of other 'scripts, please visit the site. Option Explicit Sub MarkDefaults( ByRef sDefault() ) Const csChecked = "CHECKED" 'Decide which path we should display If Request.Form("MyPath") = vbNullString Then 'An atypical default root document sDefault(0) = "/default.asp" Else 'Whatever the last path used was sDefault(0) = CStr( Request.Form("MyPath") ) End If If Request.Form("MyPathType") = "A" Then sDefault(1) = csChecked Else sDefault(2) = csChecked End If If Request.Form("MyEditMode") = "W" Then sDefault(4) = csChecked ElseIf Request.Form("MyEditMode") = "D" Then sDefault(5) = csChecked Else sDefault(3) = csChecked End If End Sub Sub AttemptExecute() Dim sFilename, sMyData, sEditMode Dim objFSO, oInStream 'Get and prepare the edit mode variable sEditMode = CStr( Request.Form("MyEditMode") ) 'Define the constants used by the FSO Const ForWriting = 2, ForReading = 1 'Check we actually have a path passed to us If CStr( Request.Form("MyPath") ) <> vbNullString Then 'Handle relative and absolute paths If CStr( Request.Form("MyPathType") ) = "R" Then sFilename = Server.MapPath( CStr( Request.Form("MyPath") ) ) Else sFilename = CStr( Request.Form("MyPath") ) End If 'Generate our FSO, note the error handler begins after this ' call so if it does error you get a server message rather ' than handling it in the code Set objFSO = CreateObject("Scripting.FileSystemObject") On Error Resume Next 'Handle various modes the script has If sEditMode = "W" Then 'Write to a file 'Open the file for writing, create it if it does not exist Set oInStream = objFSO.OpenTextFile( sFilename, ForWriting, True ) 'Check for errors If Err.number = 0 Then oInStream.Write Request.Form("MyFileData") oInStream.Close %> Write Attempt : Success!
<% Else %>
<% End If ElseIf sEditMode = "R" Then 'Read from a file 'Open a file for reading Set oInStream = objFSO.OpenTextFile( sFilename, ForReading, False ) 'Check for errors If Err.number = 0 Then %> <% Else %>