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);

    }

 

}

 


Similar Articles