BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Delete A File In ASP.NET?

To delete a file on server you can use code like this:

[ C# ]

// We need this namespace
using System.IO;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string FileToDelete;
        // Set full path to file
        FileToDelete = Server.MapPath("~/Files/SomeFile.txt");
        // Delete a file
        File.Delete(FileToDelete);
    }
 
}

[ VB.NET ]

' We need this namespace
Imports System.IO
 
Partial Class _Default
  Inherits System.Web.UI.Page
 
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
    Dim FileToDelete As String
    ' Set full path to file
    FileToDelete = Server.MapPath("~/Files/SomeFile.txt")
    ' Delete a file
    File.Delete(FileToDelete)
 
  End Sub
 
...
 
End Class



Related articles:

1. Introduction To Assemblies

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.