c# - Exception when a path to a file is null (when you cancel OpenFiledDalog) -
this code:
openfiledialog openfiledialog1 = new openfiledialog(); dialogresult result = openfiledialog1.showdialog(); // show dialog. if (result == dialogresult.ok) // test result. { string file = openfiledialog1.filename; } else { messagebox.show("error."); } //later on.. datatable lertableec0 = new datatable(); lertableec0.readxml(openfiledialog1.filename);
and right here in end comes error, works fine, xml import, etc if cancel in open dialog exception, hint?
(there ir similar question answer still confusing me
return null;
didnt work me
if (result == dialogresult.ok) // test result. { string file = openfiledialog1.filename; datatable lertableec0 = new datatable(); lertableec0.readxml(openfiledialog1.filename); } else { messagebox.show("error."); }
since filename not set if cancel button clicked , empty string passed readxml()
function throws exception . have move function inside ok click condition
Comments
Post a Comment