Friday, April 24, 2020

Remove Files From Folder in asp.net c#


In this post i will going to show how to delete file and image from the folder or directory using asp.net c#.

Add the following button code in asp web page

 <asp:Button ID="btnDeleteFile" runat="server" Text="Delete" OnClick="btnDeleteFile_Click"/>


Add definition of btnDeleteFile_Click in cs file of web page


protected void btnDeleteFile_Click(object sender, EventArgs e)

        {

            string FolderPath ="";

//set the folder path where files are exists
            FolderPath += "Uploads/10_New_file_1.jpg";

            string path = Server.MapPath(FolderPath);

            FileInfo file = new FileInfo(path);

            if (file.Exists)//check file exsit or not

            {

                file.Delete();

            }

        }


Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...