I am selecting file from openfiledialoge and displaying it in picturebox and its name in textbox when I click on delete button I am getting exception The
delete
The
use this code
string imgName = ofd.SafeFileName; if (Directory.Exists(path)) { var directory = new DirectoryInfo(path); foreach (FileInfo file in directory.GetFiles()) { GC.Collect(); GC.WaitForPendingFinalizers(); file.Delete(); } }