Delete Files in ASP.Net

To delete the files, First we need to get the folder name and file name, then apply a condition to check that file exists on this location or not. If file exists then call the method to delete the file. The Namespace using System.IO; must be use to operate File operations to Add/Delete/Move etc

public string DeleteFile(string FileName)
    {
        string strMessage = "";
        try
        {
            string strPath = Path.Combine(FolderName FileName);
            if (File.Exists(Server.MapPath(strPath)) == true)
            {
                File.Delete(Server.MapPath(strPath));
                strMessage = "File Deleted";

            }
            else
                strMessage = "File Not Found";
        }
        catch (Exception ex)
        {
            strMessage = ex.Message;
        }
        return strMessage;
    }

Related Alrticles

FREE!!! Registration