Groups | Blog | Home
all groups > visual studio .net general > september 2007 >

visual studio .net general : webbrowser in vb.net


Komandur Kannan
9/17/2007 12:42:02 AM
dear support team,
im using vb.net 2005 with dotnetframework 2.0,
im using webbrowser control to display my word doc file , here i hv few
questions?
1). how can i hide standard/drawing/ bars in webbrowser control, if i select
webbrowsershortcutenabled = false, its not doing, i checked with its other
property also, but its not hidding all the bars
2). and i need to set the default layout for the browser is WEB VIEW LAYOUT,
and other layouts ( which is in the webbrowser down bottom), i need to hide
3). if i open the readonly recommended DOC file thru browser, still its
askign for MODIFY password, if i click READONLY ( modify password is
important, since the same document is sharing with other users), its opening,
how can i set this readonly as default, whenever the application gets open,
and is it possible for me to open the same file with different users at the
same time, does it affect readonly property, advice
thanks for understanding the request
regards,
jialge NO[at]SPAM online.microsoft.com
9/17/2007 1:34:59 PM
Hello Komandur,

[quoted text, click to view]
The codeproject document:
http://www.codeproject.com/office/Embedding_Excel.asp shows a demo for your
reference.
First, we need to get the current object of Word Application (see the
method GetActiveWorkbook in ExcelWrapper of the above demo project). The
command bars could be hidden by calling ".Visible=false" on the command bar
objects of Excel application. Suppose that m_wordApplication refers to the
application object of Word.
For Each bar in m_XlApplication.CommandBars iterates all the command bars
in the application and
bar.Visible = False; makes all of them invisible. In this way, we could
also hide all the menus, taskpanes and etc.

[quoted text, click to view]
hide
In the first question, we already get the object of the current Word
application. To set the Word's layout as Web View, we could call:
m_wordApplication.ActiveWindow.View.Type = wdWebView
But I did not find a method to disable the other view types. I have sent an
email to consult the issue and will get back to you as soon as possible.

[quoted text, click to view]
I did not find any method or parameter in WebBrowser control to specify the
open type. I have sent an email to development team and check whether there
is a workaround for it.
Besides, when a file is opened and 'Modify' is allowed, the following opens
of the file can only be ReadOnly due to the lock of the file. For instance,
suppose the first user open the file with Modify, then the second user can
only open it with ReadOnly.

Please let me know if you have any other concerns, or need anything else.

Sincerely,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Komandur Kannan
9/17/2007 10:34:02 PM
Hi Ge,
well, thanks for your prompt support, and since we need to find the
workaround for my point-3, i hv to look for the convinient control otherthan
webbrowser for displaying my password protected doc file, and by default it
should take the readonly parameter for displaying it in the .net form ( their
is no modification mode in the .net form, only with ms word they can do such,
but in the form only to view the doc file content, and at the same time many
user may required to use, since it is in the welcome screen), can you advice
me which control i can use with, else does it required to create the
usercontrol, please advice in detail
thanks
Anis

[quoted text, click to view]
jialge NO[at]SPAM online.microsoft.com
9/18/2007 12:00:00 AM
Hello,

The development team confirmed that the control WebBrowser is not able to
directly open a document with ReadOnly. But Microsoft provide another
control to host Office documents: dsoFramer
http://support.microsoft.com/?id=311765
The control (source and sample) can be downloaded at
http://www.microsoft.com/downloads/details.aspx?familyid=CE2CA4FD-2169-4FAC-
82AF-770AA9B60D77&displaylang=en (Microsoft Developer Support Office Framer
Control 1.3 Sample (KB 311765))

Please NOTE: there are some known issues of dsoFramer when it is used to
open Excel workbooks. For instance, it might throw an exception: The
document is not associated with an ActiveX Document server.

The control itself is developed in Visual C++ and it exposes its own
interfaces for Open/Save/Create Office documents. The samples are written
in VB and VB.NET. They show how to use the control to open doc/xls/ppt in
Windows form or web form.

Take the project Vb7TestApp as an example here:
In the sub btnOpenFile_Click of Form1.vb, it creates an object of dsoFramer
(AxFramerControl)
Dim ctl As AxDSOFramer.AxFramerControl
ctl = GetFramerCtlFromIdx(idx)

Then use the control to open a document:
ctl.Open(OFileDialog.FileName)
The control opens file with Modify by default. To make it open with
ReadOnly, we could specify the parameter 'ReadOnly' in the Open method:
ctl.Open(OFileDialog.FileName, True, Type.Missing, Type.Missing,
Type.Missing)
In this way, the doc files with Modify password will be opened without the
password dialog popped out.

In order to hide all the menus, command bars, etc in the control, please
add the following codes after the creation of ctl
ctl.Menubar = False
ctl.Titlebar = False
ctl.Toolbars = False

In order to set the default view of doc as Web View, please add the code
below after the ctl.Open
ctl.ActiveDocument.ActiveWindow.View.Type = 6

When a word document is opened, even with ReadOnly, a edit lock will be
added to the file. If the document is not closed, the next open of the file
will pop out a dialog that says the file is edit locked by another user.
Therefore, if multiple users want to open the file, we could copy the doc
from server to user's clients first, so as to avoid such dialogs.

For more information about dsoFramer, please refer to the KB article
http://support.microsoft.com/?id=311765
If you have any other concern or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
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.
Komandur Kannan
9/18/2007 6:00:04 AM
Hi,
thanks for support and suggestion,
well, as you said,...

When a word document is opened, even with ReadOnly, a edit lock will be
added to the file. If the document is not closed, the next open of the file
will pop out a dialog that says the file is edit locked by another user.
Therefore, if multiple users want to open the file, we could copy the doc
from server to user's clients first, so as to avoid such dialogs.

--- this is very difficult, since the data entry operator may fill this doc
file by often to give some information for the operations team working
around, only one data entry operator will do update this file and the number
of users may required to use this file as the INFORMATIVE for their daily job
routine, so 24/7 operations team is working with the application background
of this doc file and whenever required the data entry operator may required
to update the file, so only one place for modifications and n number of users
for the readonly mode,
here the quite complication why i feel is, the operations team is working
in different places to access the file, so its difficult for me to give
updations for all the client machine manually whenever the changes happend,
is it any workaround for this.. and the doc file is with security and with
pictures and well formatted text for data ( its basically a information),
plz advice
thanks in advance for understanding the request
Anis

[quoted text, click to view]
jialge NO[at]SPAM online.microsoft.com
9/19/2007 12:00:00 AM
Hello Anis,

The control RichTextBox is not able to load a doc file. The operation
FileCopy(lConststrDestDocFileNm, lConststrDoc) just changes the file name
of the doc, it is not changing its file format. Word can still load the
IConststrDoc because Word is able to load both doc and rtf and it still
regards the file as doc internally. In order to convert the doc to rtf, a
work around is to automate Word to open the doc and save as rtf. Below is a
doc to rtf converter for your reference:

using System;

namespace DocConvert

{
class DoctoRtf
{
static void Main()
{

Word.Application newApp = new Word.Application();
object Source="c:abcSource.doc";
object Target="c:abcTarget.rtf";

object Unknown =Type.Missing;

newApp.Documents.Open(ref Source,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown );

object format = Word.WdSaveFormat.wdFormatRTF;
newApp.ActiveDocument.SaveAs(ref Target,ref format,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown);

newApp.Quit(ref Unknown,ref Unknown,ref Unknown);
}
}
}

If you have any other concern or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
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.
Komandur Kannan
9/19/2007 12:30:01 AM
Hi Jialiang,
Thanks for your support and suggestions, its quite nice and useful, i will
do the same, thanks for your support again
regards,
Anis

[quoted text, click to view]
Komandur Kannan
9/19/2007 3:12:03 AM
Hi jialiang,
i hv a question regd. this again, sorry for the inconvinience,
how can i change the doc format into rtf format, why im asking this is, if
the server based version comes with EDIT MODE SECURITY, when i make the local
copy, again this will go like a password protected file, so i wanted to load
as a RTF file, if i use rtf format it can be useful for 2 things
1). i can use RICHTEXTBOX to load the file directly, if its well formatted
and with the image also no problem
2). i dont want to use the dll since this control comes directly (with out
any dlls inclusion)
so when i make the filecopy in word object, i can able to convert the
format, but when i load it on the richtextbox, its saying the "invalid file
format", how can i resolve this..
----- code sample wht i did
Private Sub lprSubCopyDocInLcl()
Try
objWord = CreateObject(lConststrWordObj)
objWord.DisplayAlerts = False
FileCopy(lConststrDestDocFileNm, lConststrDoc)
objWord = Nothing
lrtxHelpLine.LoadFile(lConststrDoc)

Catch ex As Exception
lrtxHelpLine.Text = "Error Loading User Guide"
End Try

End Sub

** declaration
Private Const lConststrDestDocFileNm As String =
"H:\template\User_Guide.doc"
Private Const lConststrWordObj As String = "Word.Application"
Dim lConststrDoc As String = "c:\Dos\userG.rtf"
Dim objWord As Object
---- end code sample
thanks in advance
regards,
Anis

[quoted text, click to view]
jialge NO[at]SPAM online.microsoft.com
9/19/2007 3:12:42 AM
Hello Anis,

I feel sorry for making you misunderstand my meaning. I suppose that your
windows form application is deployed in clients and the document is in the
server. Is it right? Every time when clients decide to open/read the
document with the winform, for instance, the client clicks a button 'Open'
and triggers the OnClick event, I think we could,
first, copy the document from server to a local directory (Put File.Copy at
the beginning of OnClick event handler);
then, use dsoFramer control to open the local copy of the doc.
In this way, the clients will always read the up-to-date file from the
server and no 'Edit lock' conflict will occur. Of course, the data entry
operator, who does the update of the source file, should operate directly
on the server's file.

Actually, if you use the WebBrowser control to open the doc from server,
internally, the control will also make a copy of the file to a local temp
directory and open the local file instead.

If you have any other concern or need anything else, please feel free to
let me know.

Sincerely,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
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.
Komandur Kannan
9/19/2007 6:16:01 AM
Dear Jialiang,
well, thanks for your prompt support, and based on the sample you sent,
their was some corrections in it, this is the working solution attached
below.. and really thanks for your prompt support and suggestion, based on
your idea, my concept i implemented and thank you very much for your support
agian
regards,
Anis

------- code
Private Sub lprSubCopyDocInLcl()
Dim Unknown As Object = Type.Missing
Dim Known As Object = True
Dim NewApp As Microsoft.Office.Interop.Word.Application = New
Microsoft.Office.Interop.Word.Application()

Try

Dim Source As String = lConststrDestDocFileNm
Dim Target As String = lConststrDoc

NewApp.Documents.Open(Source, Unknown, Known, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown)

Dim format As Object =
Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF

NewApp.ActiveDocument.SaveAs(Target, format, Unknown, Unknown,
Known, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown, Unknown,
Unknown, Unknown, Unknown, Unknown)
NewApp.Quit(Known, Unknown, Unknown)
NewApp.Quit()
NewApp = Nothing
lrtxHelpLine.LoadFile(lConststrDoc)

Catch ex As Exception
MessageBox.Show(ex.Message)
lrtxHelpLine.Text = "Error Loading PV User Guide"
NewApp.Quit(Unknown, Unknown, Unknown)
End Try

End Sub

- end code

[quoted text, click to view]
AddThis Social Bookmark Button