Word Add-In creates problems with Desktop Search Preview
Hello All,
Sorry for the long post, but I wanted to be somewhat clear. I'm developing a Word (2003) Add-In for an IM management system which handles the DocumentBeforeSave event, and runs a Windows Form to aid in attaching metadata to the document (mainly for XP). It also gives the user the ability to cancel the save event. Everything is working well with the Add-In, but when I tested it with various technologies before deploying, I found a problem with Desktop Search.
When the Desktop Search generates a preview of a word document, it triggers the DocumentBeforeSave event, thus running the form. If the user simply adds the metadata when prompted by clicking OK, there is no real problem (other than the hassle of having this popup in a preview as the form is only supposed to pop-up when the user is using the SaveAs command, which Desktop Search is doing (the SaveAsUi value is set to true)). The major problem occurs when the user cancels the save event (which seems to be many people's instinct in this context). The DocumentBeforeSave event seems to be triggered again, calling the form again. If the user cancels a 2nd time, then Desktop Search says that the Word preview is not available. Worse than this, the document remains active in the background, not appearing in the processes or on the desktop, but using the form's resources. This causes resource access problems. When shutting down, the OS asks whether you'd like to save theWord documents whose save functions were cancelled during preview. If you say no, then it complains that something called "CiceroUIWndFrame" is not responding and you must "EndNow"... Also, word recovers these documents the next time it is opened, even though the documents were not misplaced. I assume that Desktop Search is caching these in order to speed preview, and triggers the DocumentBeforeSave event in the process.
I haven't come across any easy solutions so far, (e.g. there doesn't seem to be an easy way from within Word to detect whether the event was triggered by the Desktop Search system). Since I'm deploying this in a large organization which allows modifications like individual users installing the MSN Search toolbar, I need to find a solution, and preferably one that can be solved either by network installs (e.g. a change to the toolbar that is installed on all machines) or a change to my code (thus avoiding requiring users to perform some task).
Thanks in advance (the code for the handling of the DocumentBeforeSave event follows). Craig.
try { control.ShowDialog(); } catch (Exception e) { MessageBox.Show(e.ToString()); } if(control.Dialog.DialogResult == DialogResult.Cancel) { MessageBox.Show("You must fill out the metadata form in order to save!!!\nThe save has been cancelled"); } else { Cancel = false; SaveAsUI = true; } control.CloseDialog(); } }
J_Craig
J-Craig,
We've looked into this a bit, but can't as yet, come up with a solution (there might not be a supported solution). We're going to spend a bit more time on it to see if a better answer is available.