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
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