c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

Delete file from the server using asp.net c#

| | ASP-NET , CSharp , MVC

You should make sure that the file path passing to delete from the server in asp.net c#. This following code is to delete the record from database and also from the folder path of the server.

Picture picture = db.Pictures.Find(id);
            if ((picture != null))
            {
                if (System.IO.File.Exists(Server.MapPath(picture.Path)))
                {
                   System.IO.File.Delete(Server.MapPath(picture.Path));
               }
            }
           db.Pictures.Remove(picture);
           db.SaveChanges();