Not allow user to open another same excel file while one is already opened

Hi..

I 'm working on windows application. From a Menu Item the user will open up the excel file to view the report. If the user minimizes that excel file and tries to open another from the same Menu Item , the application is going to throw exception. Is there any way to prevent this?

like for eg: when the user tries to open the excel file for the second time, show a message in the message box to close the one which is already opened.. or disable everything else on the windows form untill the opened file is closed like in message box where nothing else works ultil Ok button is clicked.

thanks.

Hi,

Thanks for considering Aspose.

Well, Aspose.Cells opens/loads excel file in read-only mode, So if a file is already opened by another user and you try to open the same file, it will throw an exception that the file is used by another process.

Thank you.

How to avoid this? and my question was what if the file is opened by the same user for the second time wihtout closing the first file.

Thanks

Hi,

Thanks for considering Aspose.

I think you may try to enclose the related code (Workbook.Open()) in try.... catch block and handle it.

E.g.,

Workbook workbook = new Workbook();
try
{
workbook.Open("d:\\test\\columnthreed.xls");
}
catch(Exception ce)
{
MessageBox.Show("Error: " + ce.Message);
return;
}
Cells cells = workbook.Worksheets[0].Cells;
Worksheet sheet = workbook.Worksheets[0];
.
.
.

Thank you.

This is not working its still showing me the same exception. Its showing me the following exception.

."The process cannot access the file 'C:\Documents and Settings\rambala\Desktop\sot\1.0 (2008)\SiteOptimizationTool\bin\Debug\RecommendedVolumeReport.xlsx' because it is being used by another process."

Thanks.

If you have already used MS Excel to open the file, Aspose.Cells will throw this exception because we cannot open an on-processing Excel file.