c# - cant try catch when delete file -


i want delete file, in case locked process though have set try catch, program still dark cash @ fi.delete(), how fix it.

a first chance exception of type 'system.unauthorizedaccessexception' occurred in mscorlib.dll

additional information: access path 'h:\j\r\sound.mp4' denied.

private void gview_cellcontentdoubleclick(object sender, datagridviewcelleventargs e) {      try     {         string cellvalue = gview.rows[e.rowindex].cells["name"].value.tostring();          var confirmresult = messagebox.show("delete item " + cellvalue,                                          "confirm delete!!",                                           messageboxbuttons.yesno);         if (confirmresult == dialogresult.yes)         {             system.io.fileinfo fi = new system.io.fileinfo(cellvalue);             fi.delete();         }         else         {          }     }     catch (unauthorizedaccessexception ex)     {         messagebox.show(ex.message);     }  } 

private void gview_cellcontentdoubleclick(object sender, datagridviewcelleventargs e) {      try     {         string cellvalue = gview.rows[e.rowindex].cells["name"].value.tostring();          var confirmresult = messagebox.show("delete item " + cellvalue,                                          "confirm delete!!",                                           messageboxbuttons.yesno);         if (confirmresult == dialogresult.yes)         {             system.io.fileinfo fi = new system.io.fileinfo(cellvalue);             fi.delete();         }         else         {          }     }     catch(system.io.ioexception)     {      // exception when file in use or other     }     catch (unauthorizedaccessexception ex)     {         messagebox.show(ex.message);     }    catch(exception ex)    {     // other    }  } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -