Howard Bash
asked on
VSTO 2010 Word Ribbon Add in Active Document Name
I need to obtain the currently loaded active document name and place it on a control (label or textbox) on a custom ribbon built using VSTO 2010.
From the add in, how can I detect the name of the active document when word launches and when a subsequent document is loaded?
From the add in, how can I detect the name of the active document when word launches and when a subsequent document is loaded?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not too familiar with Sharepoint. Can't help you there.
ASKER
Imagine you have a hyperlink on a web page and the link is just to a DOCX file. I don't think the issue is a SharePoint one. It's just where the hyperlink I am launching word from resides.
Do my suggestions not work?
ASKER
All good. I accidently requested attention. I will request that they remove "requested attention". Sorry about that.
ASKER
What I tried is to in the ThisAddin code I added:
(1)
public delegate void DocNameChanges(string NewDocName);
public event DocNameChanges docnamechanges;
and later in that module:
(2)
/// <summary>
/// Handle changing reference to current loaded document
/// </summary>
private void myDocChangeEventHandler()
{
if (Globals.ThisAddIn.Applica
{
ThisDocument = Globals.ThisAddIn.Applicat
docnamechanges(ThisDocumen
}
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
if (Globals.ThisAddIn.Applica
{
// Hook into the ThisDocument Change Event
Application.DocumentChange
}
}
(3)
And in myRibbon_Load event added the following:
//Set Handler for document change and name change
Globals.ThisAddIn.docnamec
And finally that routine:
private void HandleNameChange(string NewDocName)
{
string docExt = Globals.ThisAddIn.ThisDocu
bool bHasExtension = (bool)(NewDocName.IndexOf(
string AdjustedName = string.Empty;
switch (Globals.ThisAddIn.ThisDoc
{
case Microsoft.Office.Interop.W
if (bHasExtension)
{
AdjustedName = NewDocName;
}
else
{
AdjustedName = NewDocName + ".docx";
}
break;
case Microsoft.Office.Interop.W
if (bHasExtension)
{
AdjustedName = NewDocName;
}
else
{
AdjustedName = NewDocName + ".dotx";
}
break;
case Microsoft.Office.Interop.W
AdjustedName = NewDocName;
break;
}
this.txtSaveToFileName.Tex
this.txtUploadFileName2.Te
this.txtLocalFileSaveName.
}
All this seems to work, except when word is launched via clicking on it from a SharePoint 2010 list.