if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
DataTable lertableEC0 = new DataTable();
lertableEC0.ReadXml(openFileDialog1.FileName);
}
else {
MessageBox.Show("Error.");
}
Since filename is not set if Cancel button is clicked , empty string is passed to ReadXml()
function which throws exception . So you have to move the function inside OK click condition