File Info rare Null Reference Exception

Thursday, July 3, 2014

Hi this code is throwing Null Reference Exception, but the exception is rare its not that it is coming very often. After the object of FileInfo is properly initialized is there any way that it can still contain null. Please help me find the exact place where it is happening. Thanks in advance



SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.CheckFileExists = false;
fileDialog.Filter = "Excel Files|*.xls";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
FileInfo fileInfo = new FileInfo(fileDialog.FileName);

if(fileInfo.Exists)
{
DialogResultNemo result = MessageBoxNemo.Instance.Show("Overwrite File ?", "File already exists. Overwrite existing file ?",
MessageBoxNemoButtons.OKCancel, MessageBoxNemoIcon.Question);
if (result == DialogResultNemo.Cancel) return;
}

try
{
ExcelExporter exporter = new ExcelExporter();
exporter.Export(this, fileDialog.FileName);
}
catch (Exception)
{
MessageBoxNemo.Instance.Show("Could not write File !", "Could not write file. The file may be in use by another process.",
MessageBoxNemoButtons.OK, MessageBoxNemoIcon.Error);
}
}






http://ift.tt/1kl3Ifb