By Misty Myslinski Sub DeleteFile The delete file subroutine contains the code that allows you to delete any file from the web-server. It prompts for confirmation of delete before executing the action.
Sub DeleteFile If Request.Querystring("commit") <> "yes" Then Session("lastpage") = Request.ServerVariables("HTTP_REFERER") Session("sFile") = sFile Response.Write "<p>You are about to delete " & sFile & ". " If sFileType = "jpg" OR sFileType = "gif" Then Response.Write "<p><img src=""http://" & Request.ServerVariables("HTTP_HOST") & sfile & """></p>" End If Response.Write "<b>This action cannot be undone.</b></p>"
Response.Write "<UL>" Response.Write "<LI><a href= """ &scriptname&"?action=deletefile&path=" & sPath & "&file=" & sFile & "&commit=yes"">Continue delete</a></LI>" Response.Write "<LI><a href=" & Session("lastpage") & ">Cancel Delete</a></LI>" Response.Write "</UL>" Else fs.DeleteFile(server.mappath(Session("sFile"))) Response.Redirect("" & Session("lastpage") & "") End If End Sub
Sub DeleteFolder The delete folder subroutine contains the code that allows you to delete any folder from the web-server. It prompts for confirmation of delete before executing the action.
Sub DeleteFolder If Request.Querystring("commit") <> "yes" Then Session("lastpage") = Request.ServerVariables("HTTP_REFERER") Session("sFolder") = sFolder Response.Write "<p>You are about to delete " & sFolder & ". " Response.Write "<b>This action cannot be undone.</b></p>" Response.Write "<UL>" Response.Write "<LI><a href= """ &scriptname&"?action=deletefolder&path=" & sPath & "&folder=" & sFolder & "&commit=yes"">Continue delete</a></LI>" Response.Write "<LI><a href=" & Session("lastpage") & ">Cancel Delete</a></LI>" Response.Write "</UL>" Else Response.Write sPath & "<br>"
Response.Write sFile & "<br>" fs.DeleteFolder(server.mappath(Session("sFolder"))) Response.Redirect("" & Session("lastpage") & "") End If End Sub
Sub FileTypeUnsupported The file type unsupported subroutine contains the code that displays an error message when attempting to access an unsupported file (non-text or database files at this time). If the file is an image, it is displayed in-line.
Sub FileTypeUnsupported Session("lastpage") = Request.ServerVariables("HTTP_REFERER") Response.Write "The file you have selected is not available for editing in this system." Response.Write "<br>" If sFileType = "jpg" OR sFileType = "gif" Then Response.Write "<p><img src=""http://" & Request.ServerVariables("HTTP_HOST") & sfile & """></p>" End If Response.Write "<a href=" & Session("lastpage") & ">Return to Previous</a>" End Sub
Sub Size(Item) The size subroutine is called by the ShowList subroutine to format the sizes of folders and files that are returned into bytes, kb and mb.
Sub Size(itemsize) Response.Write "<td align=""center"" valign=""bottom"">" &vbCrLf Select case Len(itemsize) Case "1", "2", "3" Response.Write itemsize & " bytes" Case "4", "5"
, "6" Response.Write Round(itemsize/1000) & " Kb" Case "7", "8", "9" Response.Write Round(itemsize/100000) & " Mb" End Select Response.Write "</td>" &vbCrLf End Sub
Sub DisplayErrors The display errors subroutine collects all errors generated in the runtime script and displays them to the screen.
Sub DisplayErrors Response.Write "You have attempted to perform " & errornum & " prohibited action(s)." Response.Write "<ul>" & errorcode & "</ul>" & vbCrlf End Sub
Sub ShowList The show list subroutine contains the code that displays all of the folders and files contained in the current directory.
Sub ShowList ' Create the header for each page so that we know where we are in the directory structure If sPath = "/" Then Response.Write "<H1>Root</H1>" &vbCrLf Else Response.Write "<H1>" & sPath & "</H1>" & vbCrLf End If
' Create an upwards navigation link if we are not at the top level of the directory structure If sPath <> "/" Then Response.Write "<p><a href= """ &scriptname&"?action=viewfolder&path=" & fs.GetParentFolderName(sPath) & """>Up One Level</a>
</p>" &vbCrLf End If
' Start building the table to display the information we retrieve about the files and folders in the current directory. Response.Write "<table cellpadding=""2"" cellspacing=""1"" width=""100%"">" &vbCrLf Response.Write "<tr>" &vbCrLf Response.Write "<TH>Name</TH>" &vbCrLf Response.Write "<TH>Type</TH>" &vbCrLf Response.Write "<TH>Size</TH>" &vbCrLf Response.Write "<TH>Date Created</TH>" &vbCrLf Response.Write "<TH>Last Accessed</TH>" &vbCrLf Response.Write "<TH>Last Modified</TH>" &vbCrLf Response.Write "<TH>Attributes</TH>" &vbCrLf Response.Write "<TH> </TH>" &vbCrLf Response.Write "</tr>" &vbCrLf
' Use the GetFolder method of the filesystemobject to get the contents of the directory specified in sPath Set fileobject = fs.GetFolder(server.mappath(sPath))
' Use the SubFolders property to get the folders contained in the directory specified in sPath Set foldercollection = fileobject.SubFolders
' Start the code to alternate line colors - just to make the display a little less visually confusing. lineid=0 bgcolor = "" bgcolor_off = "#FFFFFF" bgcolor_on = "#9BC0F9"
' Loop through the folders contained in the foldercollection and display their information on the page For Each folder in foldercollection ' Apply our alternating line coloring
If lineid = 0 Then bgcolor = bgcolor_off lineid = 1 Else bgcolor = bgcolor_on lineid = 0 End if Response.Write "<tr bgcolor=""#000000"">" &vbCrLf If Right(sPath,1)="/" Then
Response.Write "<td bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom""><a href= """ &scriptname&"?action=viewfolder&path=" & sPath & folder.name & """>" & folder.name & "</a></td>" & vbCrLf Else
Response.Write "<td bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom""><a href= """ &scriptname&"?action=viewfolder&path=" & sPath & "/" & folder.name & """>" & folder.name & "</a></td>" & vbCrLf End If Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">folder</td>" Call Size(folder.size)
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & folder.datecreated & "</td>" &vbCrLf Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & folder.datelastaccessed & "</td>" &vbCrLf
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & folder.datelastmodified & "</td>" &vbCrLf Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & folder.attributes & "</td>" &vbCrLf Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bo
ttom""><a href= """ &scriptname&"?action=deletefolder&path=" & sPath & "&folder=" & folder.name & """>delete</a></td>" &vbCrLf Response.Write "</tr>" &vbCrLf Next Set foldercollection=nothing
' Use the Files property to get the files contained in the directory specified in sPath Set filecollection = fileobject.Files
' Loop through the files contained in the filescollection and dislay their information on the page For Each file in filecollection ' Apply our alternating line coloring If lineid = 0 Then bgcolor = bgcolor_off lineid = 1 Else bgcolor = bgcolor_on lineid = 0 End if Response.Write "<tr>" &vbCrLf Response.Write "<td
bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom""><a href= """ &scriptname&"?action=editfile&path=" & sPath & "&file=" & file.name & "&filetype=" & Lcase(fs.GetExtensionName(file.name)) & """>" & file.name & "</a></td>" &vbCrLf Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & fs.GetExtensionName(file.name) & "</td>" &vbCrLf Call Size(file.size)
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & file.datecreated & "</td>" &vbCrLf
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & file.datelastaccessed & "</td>" &vbCrLf
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & file.datelastmodified & "</td>" &vbCrLf
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & file.attributes & "</td>" &vbCrLf
Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom""><a href= """ &scriptname&"?action=deletefile&path=" & sPath & "&file=" & file.name & "&filetype=" & Lcase(fs.GetExtensionName(file.name)) & """>delete</a></td>" &vbCrLf Response.Write "</tr>" &vbCrLf Next
' We are done displaying information about files and folders in this directory, so close the table. Response.Write "</table>" &vbCrLf
' Create controls to allow us to create a new file in the current directory
Response.Write "<p><a href= """ &scriptname&"?action=newfile&path=" & sPath & """>Create New File in this Directory</a>.</p>" &vbCrLf
' Create controls to allow us to create a new folder in the current directory Response.Write "<p><b>Create New Folder in this Directory.</b><br>" &vbCrLf Response.Write "<form method=""POST"" action= """ &scriptname&"?action=newfolder&path=" & sPath & """>" &vbCrLf Response.Write "<input type=""text"" value=""folder name"" name=""folder""></input> " &vbCrLf Response.Write "<input type=""submit"" value=""Create Folder"" name=""submit""></input></form></p>" &vbCrLf End Sub
The Author Misty Myslinski is a
hired gun (read: contractor) saving corporate america from the tedium of
menial tasks. She thinks that anything and everything should be done over
the corporate intranet and is currently working to realize her vision. She
also does freelance web-application development in her free minutes.