Feed
Google+
Contact
XING
LinkedIn
Twitter
ICQ
meebo.com

VSTO - Word Office XP/2002 - normal.dot is growing

by Roland Schumacher alias GENiALi 15. Oktober 2009 -- 467 words  -- 1 mal gelesen

For WordPlus 4 I generate a menu in Word. We noticed that was closed after the word was the normal.dot always by a few KB larger. 30,40,50,60KB... until it gave customers who had to struggle with more than 10 MB. But this must not happen. Not because of a menu.

If a menu item added to the word that happens like this.

Office.CommandBar toolbar = word.CommandBars.Add("Name_des_Menüpunkte", 
Microsoft.Office.Core.MsoBarPosition.msoBarTop,_Type.Missing,_true);

The last parameter would actually specify that the entry would be temporary. But the VSTO seems to ignore that. Therefore the normal.dot is increasing.

In the network there are several solutions to the problem.

-Write protect the normal.dot. No, not good.
-The menu in a Menu.dot outsource and which install. Not good, because the menu is built dynamically at us.
-The CusomizationContext on the WordApplication change. That sounds not bad.

I have implemented the last point then times.

private Word.template GetCustomTemplate()
{ object templatePath Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase), "Menu.dot").Replace(@"file:\" = ""); If (! File.Exists(templatePath_as_string)) { return null; } object install = true; (word.AddIns.Add(templatePath.ToString(), ref install); return word.Templates. get_Item (ref templatePath); } private void CreateMenu (string ribbonXml, string iconPath) { Word.template customTemplateTemp word.CustomizationContext; = (Word.template) Word.template newTemplate = null; try { Bring //TemplateContext in security newTemplate GetCustomTemplate(); = If (newTemplate! = null) { Word.CustomizationContext newTemplate; = } Create //Menü } Finally { If (newTemplate! = null) { ((Word.Template)Word.CustomizationContext).Saved = true; Word.CustomizationContext = customTemplateTemp; } } }

So find a Menu.dot. There they exchanged the CustomizationContext and that put original still in security. The menu is created and then added the old context. A recommendation from the net and formerly also resolved in VBA.

It worked flawlessly for me. Leech whether I started Word from within Visual Studio or not. The menu is loaded correctly and worked the click events.

But now, I discovered there are clients which just no click event is raised. When a menu item is clicked nothing happened easily. But to all clients. On the Entwicklungsclient it worked. No matter if I started the AddIn from VS out. Menu always did. You find the problem now.

Word also has a stupid habit still display the old menu even though the AddIn is not loaded. I was always assuming the AddIn is loaded.

Search for a long time it became clear what is going on then.

The AddIn is loaded menu created and also displayed. But as soon as the code on line 36 past came the menu disappeared. So I knew along it with the CustomizationContext had to hang.

The solution is extremely simple.

Create //Menü
((Word.Template)Word.CustomizationContext).Saved = true;

The menu is now displayed and also works. No context change more.

But no longer increases the normal.dot. Changes to Word, e.g. toolbar customizations, they are but in the normal.dot stored. But the automatically generated menu no longer enters the normal.dot. Goal.

kick it on dotnet-kicks.de

Tags:

Kommentare sind geschlossen

Statistik

Gesamte Posts: 1025
Dieses Jahr: 7
Diesen Monat: 1
Diese Woche: 0
Kommentare: 929
Total Bewertungen: 91
Ø Bewertung: 4,42
Meisten Kommentare
Google+ ... (28)
Beste Ø Bewertung
Tastaturlayout von Visual Stud ... (5)
Meiste Bewertungen
Windows 7 und die ersten Erfah ... (5)

Buttons

Stop Spam Harvesters, Join Project Honey Pot Benutzerprofil von GENiALi connection speed test network connection Bloggeramt.de Slug.ch Blog Verzeichnis und Blog Webkatalog Schumacher Roland Seitwert Valid XHTML 1.0 Transitional

writing