Error after chaging file access in Office 2007

A

armaSANEA

Hi,
I use Office 2007 PIA's.
I receive an exception in a very simple scenario: I open a 2007 xlsx file,
set it to read only, and then set it back to XlFileAccess.xlReadWrite. After
this I get an exception when trying to do anything with the workbook object.
Strangely, I do not receive this exception when working with Office 2003
files (compatibility mode).

Here is the code:
try
{
app = new Application();
Workbook wb = app.Workbooks.Open(@"D:\Documents\Docs\Office 2007
Samples\2007.xlsx",
0, false, Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
true, Type.Missing, Type.Missing, false, Type.Missing, Type.Missing);

wb.ChangeFileAccess(XlFileAccess.xlReadOnly, Missing.Value, false);
wb.ChangeFileAccess(XlFileAccess.xlReadWrite, Missing.Value, false);

//Exception when accesing anything on Workbook
Console.WriteLine(wb.FullName);
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}

Here is the detailed exception:
System.Runtime.InteropServices.COMException (0x80010108): The object invoked
has disconnected from its clients. (Exception from HRESULT: 0x80010108
(RPC_E_DISCONNECTED))
at Microsoft.Office.Interop.Excel.WorkbookClass.get_FullName()
at TestConsoleApplication.Program.Main(String[] args)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top