• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2094
  • Last Modified:

Disable editing of displayed word document in .net WebBrowser control

I am using C# Winforms with .net 2.0.

I need to host a microsoft word document on a winform.  I've used the WebBrowser control to successfully do this however I need to disable editing via the browser control on any displayed word document.  Is this even possible?
0
archiveau
Asked:
archiveau
  • 4
  • 4
1 Solution
 
illusioSoftware Architect / Team LeaderCommented:
I'm not sure. I've got an easy suggestion to try:
Make the word document you are showing read-only. If I'm correct, this will disable the editing...

Let me know if this doesn't work (and if it doesn't work paste some code on how you host the document, then I can look further)

Kind regards,
Peter
0
 
Glenn_MooreCommented:
Can you lock the document?
0
 
archiveauAuthor Commented:
Locking the document (i.e. making it read only) is an obvious solution which I've tried.  This doesn't disable editing i.e. you still can make changes via the browser, you just get met with a dialog asking you to save changes as usual and when you try and save your changes you are met with a further "Microsoft Office Word" dialog telling you the file is read-only which in turn asks you to save the document under a different name.  This isn't an elegant solution for my purposes.

What I would like is to disable editing of the document all together thus making the webbrowser control display the document in a read only mode which doesn't allow the user to make any changes to begin with.

I have used the dsoframer.ocx control in the past for this purpose but as I'm developing with .net and using clickonce for distribution, I don't want to distribute COM objects I need to register.  Isolating the dsoframer.ocx COM object doesn't work with  clickonce either hence the reason I'm using the webbrowser control instead.

Cheers
Paul
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
archiveauAuthor Commented:
I'm thinking the solution to my problem is not straightforward so i'm increasing the point value.
0
 
illusioSoftware Architect / Team LeaderCommented:
I have a problem letting the webbrowser object host any word document - settings on my laptop force the document to be opened in word (btw: this is something you can always encounter on any pc) so I can't realy test what I'm suggesting:

i think the solution is very easy: "Protect" the document. If you do this you can't edit it anymore (unless you unprotect it). You can do this in two ways:
1 - by using word and this means you save the document "Protected"
2 - by using a script when opening the document. you automate the word document and turn on/off the protectection dynamically (with this method you can also set the read-only dynamically, if still needed).

method 1 is the easiest thing but then you mustn't forget to do this when you make a certain document available for viewing
method 2 requires a little knowledge of the word object model (there are plenty of resources out in the field about that main methods you will need:
CreateObject ("Word.Application")
wordApp.Documents.Open ("filename" , some optional options with the readonly among them)
theDoc.Protect(wdAllowOnlyReading, false, password, false, false)
In this method you don't open a word document, you open a Java/VB script that opens the document as you wish for you (you can generate it on the fly and pass it to the DocumentStream prop)

Kind regards,
Peter
0
 
illusioSoftware Architect / Team LeaderCommented:
In the above comment I forgot:
- Even if you document is displaying outside the webbrowser - this method remains valid.

- if you protect by automation, don't forget to save before showing and after showing you can unprotect and save again - read-only flag when opening might be a problem in this scenario

Kind regards,
Peter
0
 
archiveauAuthor Commented:
Illusion, what do you mean by

"In this method you don't open a word document, you open a Java/VB script that opens the document as you wish for you (you can generate it on the fly and pass it to the DocumentStream prop)"

I'm aware the webbrowser has a DocumentStream property but I'm a little unsure as to what you mean here?

Thanks in advance

Paul
0
 
illusioSoftware Architect / Team LeaderCommented:
You create your html page (which will result in showing the document) as a stream starting from a template document of everything hard-code and then offer the stream to the webbrowser.

The html page you create in the stream contains a client-side script that must run at page_load time and that will automate word to perform the protection transformation on the word document you want and that will show the document when the protection is set. The script will change each time on a very specific point: the filename to open. An advantage of this, is that by using this technique you avoid manipulation in the addressbar of the webbrowser component (if users somehow gain access to it).

Kind regards,
Peter
0
 
archiveauAuthor Commented:
Thanks for the solution Peter.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now