Word 2010 AutoSave event detection

Add-in Express™ Support Service
That's what is more important than anything else

Word 2010 AutoSave event detection
 
Srdjan Klasnja




Posts: 12
Joined: 2014-01-10
Hello again,

As we encountered problems with AutoSave option, we use this method to verify is the Save triggered by user or is it AutoSave:

void adxWordEvents_DocumentBeforeSave(object sender, ADXHostBeforeSaveEventArgs e)
{
object oBasic = WordApp.WordBasic;
object fIsAutoSave =
oBasic.GetType().InvokeMember(
"IsAutosaveEvent",
BindingFlags.GetProperty,
null, oBasic, null);
if (int.Parse(fIsAutoSave.ToString()) != 1)
{
getActiveAddinInstance().getAnnotator().setActive(false);
}
}

It works fine with Word 2010 on Windows 7 but on Windows 8.1 it does not work.

Do you have any suggestion, or solution to detect AutoSave event?

Thanks in advance,
Srdjan
Posted 13 May, 2014 04:56:15 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Srdjan,

In what way it doesn't work? Do you get an exception?


Andrei Smolin
Add-in Express Team Leader
Posted 13 May, 2014 05:36:56 Top
Srdjan Klasnja




Posts: 12
Joined: 2014-01-10
Hi Andrei,

Thanks for prompt reply, here is more details.

We need to check if event DocumentBeforeSave is trigered by AutoSave or not.

If it is AutoSave then we should not deactivate add-in, otherwise we get un exception.

Here is exception details:

Detailed technical information follows:
?Â?Ð?ä
(Inner Exception)
Date and Time: 12/05/2014 16:48:14
Assembly Codebase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
Assembly Full Name: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Assembly Version: 4.0.0.0
Exception Source: mscorlib
Exception Type: System.Runtime.InteropServices.COMException
Exception Message: Nom inconnu. (Exception de HRESULT : 0x80020006 (DISP_E_UNKNOWNNAME))
Exception Target Site: InvokeDispMethod
---- Stack Trace ----
System.RuntimeType.InvokeDispMethod(name As String, invokeAttr As BindingFlags, target As Object, args As Object[], byrefModifiers As Boolean[], culture As Int32, namedParameters As String[])
mscorlib.dll: N 00000 (0x0) JIT
System.RuntimeType.InvokeMember(name As String, bindingFlags As BindingFlags, binder As Binder, target As Object, providedArgs As Object[], modifiers As ParameterModifier[], culture As CultureInfo, namedParams As String[])
mscorlib.dll: N 0507 (0x1FB) IL
System.Type.InvokeMember(name As String, invokeAttr As BindingFlags, binder As Binder, target As Object, args As Object[])
mscorlib.dll: N 0011 (0xB) IL
viasema_addin.AddinModule.adxWordEvents_DocumentBeforeSave(sender As Object, e As ADXHostBeforeSaveEventArgs)
mscorlib.dll: N 0019 (0x13) IL
AddinExpress.MSO.ADXWordAppEvents.DoDocumentBeforeSave(doc As Object, saveAsUI As Boolean&, cancel As Boolean&)
mscorlib.dll: N 0028 (0x1C) IL
(Outer Exception)

Assembly Codebase: file:///C:/WINDOWS/assembly/GAC_MSIL/AddinExpress.MSO.2005/7.4.4067.2005__4416dd98f0861965/AddinExpress.MSO.2005.dll
Assembly Full Name: AddinExpress.MSO.2005, Version=7.4.4067.2005, Culture=neutral, PublicKeyToken=4416dd98f0861965
Assembly Version: 7.4.4067.2005
Exception Source:
Exception Type: AddinExpress.MSO.ADXExternalException
Exception Message: An error has occurred in the code of the add-in.
Exception Target Site: La r?f?rence d'objet n'est pas d?finie à une instance d'un objet.
---- Stack Trace ----
Posted 13 May, 2014 06:04:32 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Srdjan Klasnja writes:
DISP_E_UNKNOWNNAME


Are you sure that you have Word 2010 on that system? Is Office properly updated? Do you have application from several Office versions on that system?

The other way is to intercept all Ribbon controls causing Word to save the document (and produce DocumentBeforeSave). In the event handlers you set a flag and check the flag in the DocumentBeforeSave event: if the flag is not set, the event is initiated by AutoSave.


Andrei Smolin
Add-in Express Team Leader
Posted 13 May, 2014 08:04:18 Top
Srdjan Klasnja




Posts: 12
Joined: 2014-01-10
We have Word 2010 but it is 64 bit version that fires exception (maybe that is problem not version of Windows).

If we use your sugested method can we add that flag to all events that close document, not only from ribbon?

Thanks again!
Posted 13 May, 2014 08:50:26 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
I believe yes. The idea is to have the flag set whenever a user-initiated action occurs; if the flag is not set in DocumentBeforeSave, then the action is intiated by Word itself.


Andrei Smolin
Add-in Express Team Leader
Posted 14 May, 2014 01:58:37 Top