Click here to Skip to main content
15,614,943 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

I an reading an excel file using the interop , but after opening the file and reading it while closing a dialog box comes. how can i handle it
This is what i have written so far
private void ReadExcel()
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(openFileDialog1.FileName);
            Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;

This will prevent the dialog box, but an error comes from TFS . The error is "TFS Foundation found an error while performing operation, please save the changes and restart the application"

1 solution

Have a look here: Workbook.Close method[^]

As you can see Close method has 3 inputs: SaveChanges, Filename, RouteWorkbook. In your case, the most important is: SaveChanges. It should be only true or false values, but...

MSDN wrote:
If there are changes to the workbook and the workbook appears in other open windows, this argument is ignored. If there are changes to the workbook but the workbook does not appear in any other open windows, this argument specifies whether changes should be saved, as shown in the following list.
Share this answer
Arjun Menon U.K 4-Apr-14 2:22am    
Since i am ready file, it is not open in any other window so as you said it will show a dialog. Besides its not getting removed as i can see a thread of excel.exe in task manager. So there is no way i can handle this?
Arjun Menon U.K 4-Apr-14 2:28am    
what about that TFS error
Maciej Los 4-Apr-14 2:36am    
I have no idea. Try to debug program to find out which line throws this error, then let me know.
Arjun Menon U.K 4-Apr-14 2:45am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900