g
Printer Friendly Version

editor  
BellaOnline's ASP Editor
 

DeleteFile - Deleting a File

You should be very cautious in using this function, because it allows an ASP script to permanently delete a file from your server's hard drive.

As you might imagine, there are actually many important applications for this. If you let clients load up ads onto your server, and then delete a client from your system, you can use DeleteFile to remove all those ad graphics. If you create online postcards, DeleteFile can let you sweep out the old ones each month.

Really, only two lines are necessary for this function:

Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
ScriptObject.DeleteFile(filename)

You do of course have to set the "filename" variable to be a valid filename! :) You can either hard code this to be a certain file if you know what file will be deleted, you can take it as input from a form, or you can loop through a sequence of known values (if for example you named your postcards post1.html, post2.html, post3.html, etc).

Be VERY cautious that you never just let this function take in any file name at all. Hackers could then easily send in important file names and destroy your website.

This site needs an editor - click to learn more!

ASP Site @ BellaOnline
View This Article in Regular Layout

Content copyright © 2013 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact Editor Wanted for details.



| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor