Word 2003 Addin Menu Problem.

B

Brian

I have an incredibly frustrating problem with a Word 2003 .NET Addin. I've
been working on an internal document repository to store our documents in a
centrally managed Access (for now) and eventually SQL Server database. To
make this easier, I developed a word addin that would allow our users to be
able to upload documents to the repository without leaving word. To do this,
I created a CommandBar and added it to the "Menu Bar" of word, attached to
that a CommandBarPopup and two CommandBarButton's. On the click handler for
the CommandBarButton, it presents the user to select from a list of documents
in the DOCMGR. Once the user selects their document, the Click Events for the
buttons seem to no longer be working. Here is the code that gets called to
activate the document.


public void ActivateDocument(Document slDoc, ServerConnection psc)
{


try
{
Document slDocDeep = psc.DocumentManager.getDocument(slDoc.id);


FileStream fs = new FileStream(slDocDeep.filename, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(slDocDeep.document, 0, slDocDeep.document.Length);
bw.Flush();
bw.Close();
fs.Close(); // Already done by bw?

object missing = Type.Missing;
object filepath = Path.GetFullPath(slDoc.filename);
wdDoc = wordApp.Documents.Open(ref filepath,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);

// Lets try re-wiring the event handlers...
// if(menuBar == null)
// menuBar = wdDoc.Application.CommandBars["Menu Bar"];
// foreach (CommandBarControl menuItem in menuBar.Controls)
// {
// if (menuItem.Caption == MENU_ITEM_DOCMGRMENU)
// {
// popup = (CommandBarPopup)menuItem;
// foreach (CommandBarControl cbc in popup.Controls)
// {
// try
// {
// CommandBarButton bn = (CommandBarButton)cbc;
// if(bn.Caption == MENU_ITEM_SEND_TO_DOCMGR)
// bn.Click += new
_CommandBarButtonEvents_ClickEventHandler(bnSendToDocMgr_Click);
// else if (bn.Caption == MENU_ITEM_OPEN_FROM_DOCMGR)
// bn.Click += new
_CommandBarButtonEvents_ClickEventHandler(bnOpenFromDocMgr_Click);
// else
// MessageBox.Show("Unable to wire it up: " + bn.Caption);
// }
// catch(Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
// }
// }
// }

//wdDoc.Activate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
// try
// {
// if (wdDoc != null)
// while(Marshal.ReleaseComObject(wdDoc) > 0);
// }
// catch(Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
}
}

Any help would be greatly appreciated
 
A

Alex

There is no need to repost your problem 3 times.

See one of the other threads for my comments.


Best wishes,
Alex.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?QnJpYW4=?=,
Well, I just wanted to make sure someone heard my cry for help. :)
Then a single cross-post to a couple of groups, rather than multiple
single posts is better. Those who use "proper" newsreaders will then
pick up the post only once. And answers made in any group will show
up in the other groups, so that no one will duplicate effort :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top