all groups > dotnet interop > june 2007 >
You're in the

dotnet interop

group:

Read-Only Word document in AxWebBrowser


Read-Only Word document in AxWebBrowser craigeandrews NO[at]SPAM gmail.com
6/29/2007 1:24:35 AM
dotnet interop:
Hi,

I've been trying to find a way to host a 'view' of a Word document in
a Windows Forms app. Ideally I'd like it to be just the document; no
controls or toolbars, and certainly no editing functionality. It seems
that the recommended way is to us the WebBrowser control, and to be
able to access the document once opened, the AxWebBrowser control.

I have the document opening in the web browser control using the
Navigate method and a handler on the NavigateComplete2 event. Getting
the Word document is simple enough, and removing unwanted UI elements
such as toolbars and rules is also easy. However, I can't figure out
how to force the web browser control to open the document read only.
It seems that in the Word object model, the read only flag is a
parameter to the Application.Documents.Open() method, which I never
call thanks to the Navigate interface of the web browser.

Is there a way to force the document to be read only? I thought about
using the document properties, to no avail.

A secondary query I have is that I can't figure out how to remove the
view selection buttons from the horizontal scrollbar without removing
the entire scrollbar. I'd like the view locked to the Print View, and
don't want the user changing.

Any help would be greatly appreciated.

Thanks,

Craig
Re: Read-Only Word document in AxWebBrowser kris
7/4/2007 12:00:00 AM
Hi Craig,

I was trying the similar thing last week and i wasn't able to open the word
document in the browser window....
The word document opens outside the browser.

can you please send me the code snippet on how i can open the word doc in
the browser?

Thanks
Kris

[quoted text, click to view]

Re: Read-Only Word document in AxWebBrowser craigeandrews NO[at]SPAM gmail.com
7/4/2007 3:16:40 AM
[quoted text, click to view]

Hi Kris,

I have seen this happen a few times. I used this code:

String strFileName;

//Find the Office document.
openFileDialog1.FileName = "";
openFileDialog1.ShowDialog();
strFileName = openFileDialog1.FileName;
if (strFileName.Length != 0)
{
axWebBrowser1.Navigate(strFileName);
}

This usually works, but if I double-click the file in the open dialog
it will open in an external Word instance. If I select the document
and click OK it will pass the string back properly. This seems to be a
bug in the default implementation of the File dialog rather than the
web browser control.

The only other time I have seen the document open outside the browser
window is when I used the Windows Forms WebBrowser control. It seemed
to try and save the document to the desktop instead of open it, and
when I tried to force it open it opened externally.

On the subject of making a document read only, I found that using the
Document.Protect() method seems to be the way to go. Unfortunate, if
the user presses a key when the document is protected it makes a task
pane appear in the middle of your app ... not ideal, and there doesn't
seem to be a way around it.

HTH,

Craig
Re: Read-Only Word document in AxWebBrowser Mark Smith
7/11/2007 8:17:00 AM
I want to something similar. I want to take information in a database
and create a word document with it. I have the information displaying
in a windows form with different tabs to show the different areas for
input. I want to be able to press a button and have the information put
into the proper format (which I will specify) and be able to save it in
a word document format. Any ideas?



AddThis Social Bookmark Button