Block Excel File from opening when running an excel process from a winform application
I have a winform application(C#.ne开发者_Python百科t) that accesses data in an excel file (MS Excel 2007) and displays it. The application accesses the excel using an OLEDB connection and executes a query to fetch the data into a dataset. The excel file is not opened during this process. The data fetch operation runs in the background and once the data is fetched the excel process is killed. There are no write operations being carried out. The excel file should not be accessible to the user.
The issue now is if the user has opened another excel file, then that allows the process initiated from the application to open the excel file and sometimes locks the excel file, denying the application from accessing it. The excel file should not be opened in such a scenario as it should not be accessible to all users. Need some kind of a check mechanism to prevent it from opening.
Need some help on this..
Thanks in advance.
I found a solution to my own question. Well, it altleast works now.
I enabled the 'Shared Workbook' option in the excel file and that did the trick. It now enables multiple access to the file and doesnot lock the file to a single connection. It is'nt opening the file either when another instance of an excel file is open.
Cheers!
精彩评论