Word behaviour different when launched via IE hyperlink

K

KeithM

Hi,

We have a COM AddIn written in .NET 1.1, C# and running on XP with Office
2003 (Version 11.0) that works with Word, Excel and Powerpoint.
The add in stores some data for each document in the metadata and displays
this in a custom
toolbar when documents are loaded.

The problem is with Word.
There is code within the AddIn to prevent end users being able to switch off
or move the toolbar around.
This code ensures that if the user were to go "View->Toolbars", our addin
would not be visible. in the list of toolbars. This all works ok usually.

However, if I click on a hyperlink to a word document from within Internet
Explorer, when Word loads the document, my toolbar is not visible and if I
go to "View->Toolbars" our add in name is now visible and it is then
possible to turn it on.
What I really have to have is for Word to load up the document and our
toolbar when launched from IE, otherwise the user can circumvent auditing we
do based on the contents of the toolbar.

I have tried deleting normal.dot for the user before launching but this does
not work.
It seems that Word might be making changes in the registry in the following
path:
HKCU\Microsoft\Office\11.0\Word\Data, in particular the 'toolbars' and
'settings' values. I cannot find any documentation on this however.

I have tried programmatically setting the toolbars 'Visible' property to
'true' in the "OnStartupComplete" handler, to no avail.
It is as though something else is happening after I have recieved the Word
connection events that is overwriting my settings when launched from IE.

If anyone can give me guidance on what I need to do to get Word working
correctly I would be exremely grateful as I have been scratching my head for
3 weeks now.

Thanks.
 
P

Peter Huang [MSFT]

Hi

Firstly I think you may try to check the link below.
http://groups.google.com/group/microsoft.public.office.developer.vba/browse_
frm/thread/390b185c9534fd21/16ca494d246ae15e?lnk=st&q=&rnum=1&hl=en#16ca494d
246ae15e

When the Word Document is loaded in IE, the behavior may be different from
the standalone Word application.

So for your scenairo, when you click on a hyperlink to a word document from
within Internet Explorer, did the Word loaded in the IE windows?
We can change that behavior to that the Word will be loaded in the
standalone Word Application.
1. Open a Folder in Windows Explorer
2. Tools/Folder Option
3. File Types
4. Locate DOC extension
5. Advanced
6. Unchecked the Browse in Same Windows

Did that contradict your idea?

Also you may try to check the link below.
http://groups.google.com/group/microsoft.public.office.developer.com.add_ins
/browse_frm/thread/fed448a223c7e71c/de75de8b5bb17301?lnk=st&q=&rnum=1&hl=en#
de75de8b5bb17301

We can create the toolbar in Addin Startup and delete it in addin shutdown,
so that the Addin will not be in the Normal.dot.
That is to say, as long as the Addin's code did not run, the toolbar will
not be added.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Keith,

Did my suggestion help you?
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

KeithM

Hi Peter, sorry for the delay replying, I have been reading the threads you
mentioned and investigating further.

To summarise now:

I had already carried out the procedure you identified for ensuring that
Word documents launched from IE hyperlinks launched as stand alone Word
applications and were not displayed in an IE window.

In your second thread you recommended, I took some code you had posted and
made my own AddIn using that code, but in C#. I reproduce that code for you
here in case you can use it to help me further. The main difference is that
I took out the question ("Do you want to create toolbar") so that the Addin
is always created.
I installed the Addin and carried out the tests:

1. Delete Normal.dot from userdata\Application Data\Microsoft\Templates
Double click on a word document on my local hard drive from within
Windows File Explorer. Word loads the document.
Add in toolbar and button are visible.
Close word.

2. Delete normal.dot again.
Open IE with a test html page written that contains a hyperlink to the
same document I opened in test 1.
Click on the hyperlink.
A 'File Download' dialog appears asking if I want to open or save the
file. Click Open.
Word loads the document but the addin toolbar is not visible. Upon
checking under "View->Toolbars" the 'test' toolbar addin is there and can be
switched on.

What I have to have is that for scenaio as described in 2, the AddIn is
visible at startup and does not need to be switched on. Can you help me
with this?

Thanks.

Here is the code for the connect.cs file and the html file:

using System;
using System.Reflection;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using Microsoft.Office.Core;
using Extensibility;


using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;

namespace Insyte.SME.OfficeAddIn2
{

#region Read me for Add-in installation and setup information.
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such as:
// 1) You moved this project to a computer other than which is was
originally created on.
// 2) You chose 'Yes' when presented with a message asking if you wish to
remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the MyAddin21Setup
project
// by right clicking the project in the Solution Explorer, then choosing
install.
#endregion

/// <summary>
/// The object for implementing an Add-in.
/// </summary>
/// <seealso class='IDTExtensibility2' />
[GuidAttribute("5EAB610A-A7BD-4488-AA75-BB09CDA71489"),
ProgId("OfficeAddin2.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{

Word.Application wdApp;

public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode,
object addInInst, ref System.Array custom)
{
wdApp = (Word.Application)application;
Debug.WriteLine("OnConnection");
if(connectMode != ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}

public void OnBeginShutdown(ref System.Array custom)
{
Microsoft.Office.Core.CommandBar cmBar = null;
Microsoft.Office.Core.CommandBarButton cbb = null;
Debug.WriteLine("OnBeginShutdown");
try
{
cmBar = wdApp.CommandBars["Test"];
if(cmBar != null)
{
cbb = (CommandBarButton) cmBar.FindControl(null, null, "TestTag", null,
null) ;
}
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString()) ;
MessageBox.Show("Error on Shutdown :" + ex.ToString());
}
if(cbb != null)
{
cbb.Delete(true) ;
}
if(cmBar != null)
{
cmBar.Delete() ;
}
Marshal.ReleaseComObject(cbb) ;
Marshal.ReleaseComObject(cmBar);
cbb = null;
cmBar = null;
}

public void OnAddInsUpdate(ref System.Array custom)
{
Debug.WriteLine("OnAddInsUpdate") ;
}

public void OnStartupComplete(ref System.Array custom)
{
Debug.WriteLine("OnStartupComplete");
Microsoft.Office.Core.CommandBar cmBar = null;
Microsoft.Office.Core.CommandBarButton cbb = null;

cmBar = wdApp.CommandBars.Add("Test", null, null, (object)true);
cmBar.Visible = true;
cmBar.Position = MsoBarPosition.msoBarTop;
try
{
cbb = (CommandBarButton)
cmBar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton,
Missing.Value,
Missing.Value,
Missing.Value,
(object)true);
}
catch(Exception ex)
{
MessageBox.Show("OnStartup Error :" + ex.ToString());
}
cbb.Caption = "TestBar" ;
cbb.FaceId = 17 ;
cbb.Tag = "TestTag" ;
Debug.WriteLine("Create Toolbar Complete") ;

Marshal.ReleaseComObject(cbb) ;
Marshal.ReleaseComObject(cmBar) ;
cbb = null ;
cmBar = null;
}

public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
Debug.WriteLine("OnDisconnection");
if(disconnectMode != ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom) ;
}
}
}
}

--
html file:

<html>
<head>
</head>
<body>
<a href="\\Homer\PublicArea\Test.doc"<body>Click it! WORD DOC</a>
</body>
</html>
 
P

Peter Huang [MSFT]

Hi Keith,

Thanks for your quickly reply!
So far I can reproduce the problem and I am researching the issue and reply
to you ASAP.


Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang [MSFT]

Hi Keith,

I am sorry for delay response!
This seems to be complex issue for further troubleshooting the issue, can
you let me your Email address.
Or you may just send a Email to me via removing "online" from my Email
address.

Thanks!

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

KeithM

For interest to future readers (if any) of this post, I present the final
fix as received from MS Tech Support for the benefit of the community:

When opening a Microsoft Word document via a URL, Internet Explorer executes
code to switch out/hide the Microsoft Word toolbars so that they aren't
displayed. In order to overcome this, please try the following and let me
know if this helps:
Hook one of Microsoft Word's events, such as the DocumentChange event from
within your add-in and then execute code on the DocumentChange event to set
the visible property for the toolbar. If you were to implement this option
you would also want to add a global counter or boolean variable that you
could use to minimize the additional overhead from adding this code to the
event. For example, I added a boolean variable to the addin and initialized
it to False. In the DocumentChange event, I added code to check the value
of this variable and if it was false to then execute code to make the
toolbar visible. If this code succeeded, I then set the boolean variable to
True to prevent the code from being executed again.
 
C

Cindy M -WordMVP-

Hi KeithM,
For interest to future readers (if any) of this post, I present the final
fix as received from MS Tech Support for the benefit of the community:
Thank you very much Keith. It is something of a recurring topic. I've marked
it as a "keeper" :)!

Cindy Meister
 

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