shetlandbob
Programmer
I have a CFileDialog with I select a file with to load into an Spreadsheet application (Tidestone Formula One spreadsheet to be precise ), but I cannot find out how to determine if I get a share violation on the file I am trying to load. I thought that if I tested it with fopen ( "file", "rw" ) then I could capture it, but this doesn't work. fopen operates fine.
Any ideas on how I can identify a share violation??? (currently it doesn't load the file and brings up a message box saying "invalid file", i require at least be to able to handle this error better and inform the user that the file may be open somewhere else?). I cannot capture a return from the Read command as te code exits the routine immediately on the Read failure.
I've included the code I use below:
Any ideas on how I can identify a share violation??? (currently it doesn't load the file and brings up a message box saying "invalid file", i require at least be to able to handle this error better and inform the user that the file may be open somewhere else?). I cannot capture a return from the Read command as te code exits the routine immediately on the Read failure.
I've included the code I use below:
Code:
void CTPP9Dlg::OnFileLoadExcel()
{
CString fileName;
CString pathName;
char fileType[]= "Excel SpreadSheet (*.xls)|*.xls|Excel 5.0/95 Workbook (*.xls)|*.xls|";
CFileDialog loadFile( true,(LPCTSTR)"xls", (LPCTSTR)fileName, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, fileType, this );
if ( loadFile.DoModal() == IDOK )
{
pathName = loadFile.GetPathName(); // path and file
FILE* file;
file = fopen ( pathName, "rw" );
if ( !file )
{
MessageBox ( "Is File Already Open?", "Warning", MB_ICONWARNING );
return;
}
else
{
fclose ( file );
}
short int type;
SpreadSheet.Read ( pathName, &type ); // Excel Workbook
if ( type != 11 )
{
if ( type != 4 ) MessageBox ( "Invalid File Format", "Warning", MB_ICONWARNING );
}
}
}