Delete Method

Object: SoftArtisans.FileUp
Syntax: Delete([in,optional] Filename As String)
Description:

This method deletes a file from the web server's hard disk.

If you specify a Filename, it must contain the entire valid path.

If you do not specify a Filename, the current uploaded file is deleted. This allows you to effectively cancel an upload. If there is more than one file being uploaded in a single page, only the first one is deleted.

To delete multiple files in a single upload, there is an equivalent method for each file object, i.e., fileUpload.Form("File1").Delete. Please see SAFile.Delete().

Examples:
ASP <%
fileUpload.Delete Server.MapPath("Uploads\UploadedFile.txt")
%>
C# fileUpload.Delete(Server.MapPath("Uploads\\UploadedFile.txt"));
VB.NET fileUpload.Delete(Server.MapPath("Uploads\UploadedFile.txt"))

ASP <%
fileUpload.SaveAs strFileName
If Err = 0 Then
Response.Write("Upload saved successfully to " &_
fileUpload.ServerName & "<br />")

'--- Perform some other processing here,
'--- such as writing to a database.
'--- Assume some error occurred
'--- delete the uploaded file.
fileUpload.Delete

If Err <> 0 Then
Response.Write("An error occurred when attempting " & _
to delete the uploaded file.<br />")
Else
Response.Write("Uploaded file has been deleted.<br />")
End If

End If
%>
C# fileUpload.SaveAs(strFileName);
results.Append("Upload saved successfully to " +
fileUpload.ServerName & "<br />");

//--- Perform some other processing here,
//--- such as writing to a database.

try
{
//--- Assume some error occurred
//--- delete the uploaded file.
fileUpload.Delete();
Results.Append("Uploaded file has been deleted.<br />");
}
catch (Exception e)
{
Results.Append("An error occurred when attempting " +
"to delete the uploaded file.<br />");
}
VB.NET fileUpload.SaveAs(strFileName)
results.Append("Upload saved successfully to " + _
fileUpload.ServerName & "<br />")

'--- Perform some other processing here,
'--- such as writing to a database.

Try
//--- Assume some error occurred
//--- delete the uploaded file.
fileUpload.Delete()
Results.Append("Uploaded file has been deleted.<br />")
Catch (Exception e)
Results.Append("An error occurred when attempting " + _
"to delete the uploaded file.<br />")
End Try

Copyright © 2010 SoftArtisans, Inc. All rights reserved.