ASP Is Fun

Learning ASP
Free Course
Basics
Functions
SQL Commands
Sample Code

Servers / Setup
Host Reviews
Server Setup
Error Tips

Contract ASP
Development

Intro to ASP



 
Irish Romance


Deleting a File with ASP



ASP can do file operations, so you can allow users to add, edit and delete files using a web browser. Here is how you would delete a file.

First, you need to get a map to the actual file on the server's hard drive. Let's say you let your users load photos onto your site for some reason. You would let them choose the actual photo from a list on a webpage, and then construct the full path from that name they chose.

PhotoFile = "/photos/" & PhotoURL
PhotoPath = Server.MapPath(PhotoFile)

Now that you have a full path to that file, it's time to give the deletion command. Always make sure you check that a file exists before trying to delete it.

dim ServerFSO
Set ServerFSO=Server.CreateObject("Scripting.FileSystemObject")
if ServerFSO.FileExists(PhotoPath) then
ServerFSO.DeleteFile(PhotoPath)
end if
set ServerFSO=nothing

That's it! The file is now deleted from your server. Of course, make sure you somehow ensure that only people with proper access are in those webpages, deleting things :)

ASP File Function List


ASP Main Page | ASP Ebooks | Free ASP Course | Contact Lisa
All content copyright © 2008 Minerva WebWorks LLC. All rights reserved.



Free Newsletter!

Ebooks
Intro to ASP
ASP SQL DB
Members
Shopping


Introduction to ASP

Romance Tips
Irish Romance
Italian Romance
French Romance

ASP Poll
How do you handle 500 errors?
I don't
Page does nothing
Displays error
Emails error