View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
armaSANEA armaSANEA is offline
external usenet poster
 
Posts: 3
Default Error after chaging file access in Office 2007

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_F ullName()
at TestConsoleApplication.Program.Main(String[] args)