Deleting File which is displayed in picturebox

前端 未结 5 1295
北海茫月
北海茫月 2021-01-17 15:39

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

5条回答
  •  死守一世寂寞
    2021-01-17 16:18

    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();
                    }
                }
    

提交回复
热议问题