Hello !
There is some code that generates a file. By clicking on the Button , this file is downloaded. I want to make it removed from the server.
I wrote this code here:
public ActionResult DeleteAllFiles(string path) { DirectoryInfo directory = new DirectoryInfo(Server.MapPath(@"~/Content/")); var files = directory.GetFiles().ToList(); foreach (var deletedFile in files) { if (deletedFile.Extension == ".jpg") { try { if (deletedFile.Exists) { System.IO.File.Delete(deletedFile.FullName); } } catch (Exception e) { return View("Error" + e); } } return View(); } I do not quite understand where I need to use it. That is, that would not be such an error:
the file is busy by another process or the action cannot be performed because this file is open in Program_Name
UPD:
What are the ways to get the path to the files on the server? That is, how can I get the path to the generated file. Thank !
Server.MapPath- Igor