locked
Remove image from Image folder RRS feed

  • Question

  • User1694748171 posted

    I allowed user to uploaded image and save it to the Image folder in the server and I'm using 

       string _FileName = Path.GetFileName(file.FileName);
                    string _path = Path.Combine(Server.MapPath("~/Images"), _FileName);
                    file.SaveAs(_path);
                    ViewBag.Image = "Image Uploaded Successfully!!";

    and its work great.

    I have new requirement  that I need to give user ability to remove the image from Image folder.

    any Idea ?

    Friday, February 5, 2021 1:58 PM

Answers

  • User475983607 posted

    I allowed user to uploaded image and save it to the Image folder in the server and I'm using 

       string _FileName = Path.GetFileName(file.FileName);
                    string _path = Path.Combine(Server.MapPath("~/Images"), _FileName);
                    file.SaveAs(_path);
                    ViewBag.Image = "Image Uploaded Successfully!!";

    and its work great.

    I have new requirement  that I need to give user ability to remove the image from Image folder.

    any Idea ?

    Deleting a file is very simple and covered in the System.IO namespace.   All you need is the file path.

    https://docs.microsoft.com/en-us/dotnet/api/system.io.file.delete?view=net-5.0

    What exactly is the problem? 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 5, 2021 2:08 PM

All replies

  • User475983607 posted

    I allowed user to uploaded image and save it to the Image folder in the server and I'm using 

       string _FileName = Path.GetFileName(file.FileName);
                    string _path = Path.Combine(Server.MapPath("~/Images"), _FileName);
                    file.SaveAs(_path);
                    ViewBag.Image = "Image Uploaded Successfully!!";

    and its work great.

    I have new requirement  that I need to give user ability to remove the image from Image folder.

    any Idea ?

    Deleting a file is very simple and covered in the System.IO namespace.   All you need is the file path.

    https://docs.microsoft.com/en-us/dotnet/api/system.io.file.delete?view=net-5.0

    What exactly is the problem? 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 5, 2021 2:08 PM
  • User1694748171 posted

    I'm using System.IO as you mentioned and its work great. thx

       string _FileName = Path.GetFileName(Img_Name);
                    string _path = Path.Combine(Server.MapPath("~/Images"), _FileName);
                    System.IO.File.Delete(_path);

    Friday, February 5, 2021 7:05 PM