Here is my load routine.
private void btnLoad_Click(object sender, EventArgs e)
{
// Process Spreadsheet
btnLoad.Enabled = false;
if (dr["LOAD_DTM"].ToString() != null)
{
clsDeletePriceListDetails.DeletePriceListDetails(dr["PRICE_LIST_HDR_ID"].ToString());
}
if (InputFileName.Text != "")
{
// Check if files exist
if (File.Exists(InputFileName.Text))
{
lblMsg.Text = "Load Started.";
Application.DoEvents();
System.IO.FileInfo filepath = new System.IO.FileInfo(InputFileName.Text);
clsGlobal.Global.Path = filepath.DirectoryName;
ProcessSpreadSheet();
btnGenerate.Enabled = true;
grpboxGenerateOttawaFile.Enabled = true;
btnLoad.Enabled = true;
}
else
{
lblMsg.Text = "File does not exist. Please select a spreadsheet file.";
return;
}
lblMsg.Text = "Load Completed.";
}
else
{
lblMsg.Text = "Please select a spreadsheet file.";
return;
}
btnGenerate.Enabled = true;
grpboxGenerateOttawaFile.Enabled = true;
}
and here is my browse button routine
private void btnFindFile_Click(object sender, EventArgs e)
{
OpenFileDialog getInputFile = new OpenFileDialog();
getInputFile.InitialDirectory = "c:\\";
getInputFile.Filter = "Excel files (*.xls)|*.xls";
getInputFile.FilterIndex = 2;
getInputFile.RestoreDirectory = true;
if (getInputFile.ShowDialog() == DialogResult.OK)
{
InputFileName.Text = getInputFile.FileName;
OutputFolder.Text = Path.GetDirectoryName(InputFileName.Text);
clsGlobal.Global.Path = OutputFolder.Text;
// update datarow global var.
dr["SRC_FILE_PATH_DESC"] = InputFileName.Text;
btnLoad.Enabled = true;
btnCompare.Enabled = false;
}
}
Or is it from user entry, in which case the error is correct: windows does not permit longer filenames (normally it is safer to stay below about 240 character to have some slack).