Best of Forum Q&A

Here are ten of the most viewed questions and answers on the VSTO Forum. Note that some of the content has been slightly edited for readability only.
1.            ClickOnce with VSTO – The application is improperly formatted
2.            Error: ‘null’ is not null or an object
3.            Intercepting Word’s message pump
4.            Microsoft Office 2003 Save My Settings Wizard
5.            Outlook PST file extraction
6.            Partial trusted call from Excel application to shared members of referenced assembly
7.            Problem of Office add-in (C#)
8.            Unable to load Outlook Add-In
9.            VSTO / Word 2003 events
10.        VSTO2005 Outlook
11.   Actions Pane Disappears
1. ClickOnce with VSTO – The application is improperly formatted.
Q:  I am trying to deploy a VSTO application using ClickOnce. I am getting the following warning in Visual Studio’s Error List.Warning 1 Assembly ‘VstoSmartTagDemo.dll.manifest’ has mismatched identity ‘VstoSmartTagDemo.manifest’, expected filename: ‘VstoSmartTagDemo.manifest.manifest’. C:ProgrammeMSBuildMicrosoft.VisualStudio.OfficeTools.targets 0 0 Note that the status bar displays the message “Publish Succeeded”.I notice that a file with an extension of “.manifest.manifest” is not being found. The extension seems a bit unusual – is this expected behaviour?When I go the publish location and click on the Application Manifest file, I get an error with the following text.Application FailedUnable to continue. The application is improperly formatted. Please contact the application publisher.I copied the text in italics at the end of this post out of the window that opened when I clicked on the Details button.I saw some posts about similar problems being caused by spaces in the application name. My application name is VstoSmartTagDemo which does not contain any spaces. I also move the project to folder that did not contain any spaced in the entire path without any change.Can anyone explain what is happening here?
A:  F5 behavior in Visual Studio—————————-
     When you build and execute a VSTO project Full Trust is given to the assembly. The trust is removed when the project is built to a new location. Thus as you found you can open the document from the build directory.
     To run your application, you must double click the document itself rather than the .application file. This is the deployment manifest for your solution. Inside the publish location is a version folder containing the assembly and application manifest.
     You must also grant Full Trust to the customization assembly. One alternative is to grant permission to the publish location provided that the location is secured. In that way publish updates are also trusted. The updates appear as new version folders in the publish location. Note: if you experience any problems re-publishing in beta 2 you may need to stop and re-start VS.
     If you are running the document on a file share or from a web server, then the document also needs Full Trust.
2. Error: ‘null’ is not null or an object
Q:  I’ve installed Visual Studio Tools for Microsoft Office 2003 on my computer. Whenever I add an Excel or Word project, the project opens and I get an error message box saying “null is not null or an object”. When I look at the ThisWorkbook.vb file, I see a lot of squiggly lines indicating errors — the required references are not added to the project.I have installed Visual Tools and Office Professional 2003 correctly with all the Net Programmability available on my hard drive.
A:  This sounds like a corrupt installation of the VSTO Tools for Office. Have you got the Professional SKU’s of Office installed as well as ensure that you have the PIA’s? The error you indicate is not the normal syntax “Object or Reference Not Set” is more likely for this error type in .NET. Have you got any other macros or programs running such as JavaScript, as this is a more “Java” error like syntax?
3. Intercepting Word’s message pump
Q:  I am working on intercepting Word’s message pump to determine when the user clicks on a menu so I can enable/disable items in the drop down menu. (I’ll post the code once I get it working.)I am intercepting the pump using NativeWindow. And I can get the OpusApp windo handle. But here is where I am hitting a problem.The OpusApp window gets no specific messages as the menu is first clicked. It gets a WM_PARENTNOTIFY (WM_LBUTTONDOWN) when it is clicked with the mouse – but that message is fired a lot. And it gets a WM_ENTERIDLE if it’s popped up with ALT-T (Tools menu) but that fires after the menu is displayed.I then looked at the menu child window. It gets a WM_CAPTURECHANGED message when the menu is clicked on or accessed via ALT-T. So this will work. But is this the best way to do this?And if so, will this window always have a caption of “Menu Bar”, even in non English versions of Word? And a class of MsoCommandBar? And does this hold back to Word 2000?Also, I thought there was a WM_ message when a menu was about to be dropped down. But I can’t find it in the WM_ list of messages and I can’t find a window firing a message like this.
A:  There is no easy way as the menu is drawn from the calling app and there is no hook on this event as a callback. So, you will have to intercept the message pump as commented in previous posts to then stop the WM coming through for the menu you wish to stop. Additionally, if this is a word command, then you could have a macro in a global template intercept this for you but this is awkward to deploy.
4. Microsoft Office 2003 Save My Settings Wizard
Q:  How I can save the add-in settings with ‘Microsoft Office 2003 Save My Settings Wizard’? What I should do for this?
A:  I think you are asking for the Com-Add-in Settings to be saved as these are applications that are installed on the machine. These will not be saved by the My Settings Wizard. The registry key for Com-Add-ins normally only refers to the COM Object to construct and whether to load behavior. The reg key for the Com-Add-ins is HKEY_CURRENT_USERSoftwareMicrosoftOfficeappnameAddinsxxx where appname is Word/Excel/Outlook and xxx is the com object constructed. On later versions of office there is the option of having these locations also covered in the HKEY_Local_machine as this isn’t displayed within the Applications as it is system wide.
5. Outlook PST File Extraction
Q:  Does anyone know how to open outlook PST files and extract the contents to another format? For example, a database. I need to periodically receive PST files, extract the contents from them and store them in a database. Outlook automation is not the best option because it prompts you to allow anonymous access before letting you process and email. I would like no use interaction if possible.
A:  The automation is the best way at present. What is the email source? Is this Exchange? If so, you could look at using CDO and/or if you need to extract, you can use MSACCESS and import the data from clicking Import Tables and selecting Outlook() and then confirming the folders you wish to use. I think this maybe a quick way to solve the issues.There are tools that use MAPIX to automate with MAPI and get access to the data which don’t prompt for Anonymous access. is a good reference to start with this.
6. Partial trusted call from Excel application to shared members of referenced assembly
Q:  In my Excel application, I use an external assembly that contains some shared members. I compiled this external assembly with AllowPartiallyTrustedCallersAttribute, but still Excel fails on calling the constructor with security exception “That assembly does not allow partially trusted callers”. Maybe somebody has an idea what I should look for. According to all docs it should work, but it fails…
A:  Are you using Visual Studio Tools for Office to create your Excel solution? If so, please note that documents and assemblies in VSTO solutions require Full Trust.
7. Problem of Office add-in (C#)
Q:  I have a problem in that I have a MS Word Add-in which works fine on the computer where I developed it (in MS Visual C# .NET) but when I try to deploy it on other machines it doesn’t work. To deploy the project I am using the Setup project from the Add-ins solution explorer as per instructions at,;EN-US;q316723I tried to isolate the problem using some simple examples. I made an add-in that simply pops-up a Message Box in the OnConnection method. This deploys fine on the target machine. Next I tried the simple add-in as outlined in the Knowledgebase article 302901, “How to build an Office COM Add-in by Using Visual C# .NET.” However, this does not deploy properly, no message boxes are displayed and no button appears on the command bar. Again, these projects work fine on the computer where I developed and built them.
A:  There is no doubt that there are a fair number of things that you need to keep in mind as you create and deploy a managed add-in for Office. It seems that you would greatly benefit from getting going with some background knowledge. Here’s a link to an article that will very useful for you:How to Build an Office COM Add-in by Using Visual C# .NET;en-us;302901
8. Unable to load Outlook Add-In
Q:  I’m unable to load any Outlook Add-In that I create. I started with the Hands-On Lab 1 and then backed off to just displaying a messagebox in Startup that just displays “Hello World”.
The message box I get in Outlook when I start Run the project using VS2005 is: “Office document customization is not available”. I select OK and go on, but my “Hello World” message box never shows. Also, when I go to the menu Tools -> Options -> Other -> Advanced Options -> COM Add-Ins, my Add-In is in the list, but when I select it, the message at the bottom of the box is “Not loaded. A runtime error occurred during the loading of the COM add-in.”
I’m wondering if this is a problem with Newsgator, which is also running and uses .NET 1.1.
Any suggestions? N.B. I was able to install and run the 1st lab on another PC that I have.
A:  NewsGator is running on .NET FX 1.1, but VSTO Outlook loader requires .NET FX 2.0 to run.
Unfortunately, .NET FX is a shared per-process resource i.e. there could not be .NET FX 1.1 and .NET FX 2.0 in the same process. Even more, if someone has already started .NET FX 1.1 it is impossible to unload this version of .NET and load another one.
According to this NewsGator support recommends locking down the version of .NET to 1.0 and 1.1 using Outlook.exe config file. This is definitely not good for VSTO Outlook add-ins – they could not run.
9. VSTO / Word 2003 events
Q:  We are working on a smart client / workflow solution with VSTO and Word 2003. In our xml schema we have elements which are occurring subsequently. For example like this:
Some heading
first block
second block
third block
fourth block
We cannot tell beforehand how many text blocks user would have. It would be handy if you could do so, that then user strikes enter key, the new text block and its placeholder would appear.
Problem:          Word 2003 + Enter
Description:      After InsertParagraph (=keypress Enter) add Tags outside Paragraph
How to:           Capture KeyDown event word 2003 or capture InsertParagraph event  
A:  There is no way from within Word to monitor the key press events, so you must work around this. Here is some code that starts a timer and monitors the number of paragraphs in the document. When a new one is added it selects the previous paragraph.
Public Class ThisDocument
    Dim pcount As Integer
    Dim WithEvents timer As New System.Windows.Forms.Timer()
    Private Sub ThisDocument_Open() Handles Me.Open
        ‘count the number of paragraphs
        pcount = Me.Paragraphs.Count
        ‘set the timer interval
        timer.Interval = 750
        ‘start the timer
    End Sub
    Private Sub ThisDocument_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    End Sub
    Private Sub ThisDocument_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
        ‘stop the timer
    End Sub
    Private Sub timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer.Tick
        If (Me.Paragraphs.Count > pcount) Then
            ‘put the added paragraph in a bookmark
            Me.Paragraphs.Item(Me.Paragraphs.Count – 1).Range.Select()
            ‘Now that you have the range of the previous paragraph you
            ‘can wrap it in a bookmark or XMLNode.
            ‘set the new count
            pcount = Me.Paragraphs.Count
            ‘TODO: manage the deletion of paragraphs
        End If
    End Sub
End Class
10. VSTO2005 Outlook
Q:  I have a VSTO2005 Outlook add-in that creates a toolbar in Outlook at startup. The toolbar includes several buttons. I now want to create and make visible a different toolbar when users open or create a task, e-mail or appointment.
A:  CommandBars can be made visible and invisible. You simply need to set the Visible property to True or False depending on your conditions. Use the Explorer.FolderSwitch event to change your toolbar visibility.
11. Actions Pane Disappears
Q:   I have an Excel Template solution developed using VSTO 2005 that has controls on the
      Action Pane.  I have a custom menu button that the user can use to toggel the Action pane on
      and off, and everything works fine until the user attempts to open an additional Excel file. 
      If a user opens another Excel file from Windows Explorer by double clicking or selecting open
      from the context menu, the Actions Pane goes away.  I then switch back to the original VSTO
      document, and using my menu button attempt to restore the action pane.
A:  In the VSTO customization, you can use the Workbook.Activate event.  When called from the
     Workbook.Activate, the Workbook is already in the middle of a refresh.  If you Display the
     TaskPane (and ActionsPane) in this event, it should show. 

Globals.ThisWorkbook.Application.DisplayDocumentActionTaskPane = TrueGlobals.ThisWorkbook.ActionsPane.Visible = True
     Now, so that we don’t step on the toes of your MSO CommandBars button, you should set a      token when the button is clicked.  You can use this token to track whether or not the      ActionsPane was suppose to be open or closed.  That way, when you open the next workbook      and it disappears, and then you switch back the VSTO customization you can check this token     in the Workbook.Activate event.  With this logic, you can make sure the ActionsPane doesn’t      always re-appear whenever the Workbook.Activate event fires. 


Thanks for your detailed answer about these 11 questions  , and some of them are really what i want to know eagerly._________________________________________________________________________________Cat foodCat websiteCat diseases

Can YOu help me out? I am just stuck in relating all msg file which I have extracted from pst database. I mean parent child relationship in mails. For example 1) A sends mail to B, B fwded it to C and C replies back to A. How  can I relate all these three msg. files. I am not able to find unique thing like refID replyto id or msg id in sent mails items. Awaiting… thanks