Home » VB.Net

WebBrowser Control.

Hi all

Is it possible to open a ms office file (mainly doc or xls) in a web browser control in vb.net.

I used 

mybrowser.Navigate(filepath) \\filepath include path and name of file (c:\mydoc.doc)


but it open a dialog box in which I have choices for (save ,open and cancel)


1)save : save the document

2)Open : opens the Doc in a new office document (excel or word)

3 )cancel : cancel it


But I want to open it inside the browser not in the different window or different document window


Thanks to all



5 Answers Found


Answer 2

thanks but I already visited The link  http://support.microsoft.com/kb/304643/

It is creating the same problem.

not opening the document  in the browser  but in another file  for it


Answer 3

If you read the link toward the end, you will see where it said that you cannot open  office2007 file  with webbrowser. So you might have to consider using ActiveX to host it



Answer 4

Thanks for  reply

yes I read it.

Currently I m using ms office  2003.

I also checked in open  office. but same results.


Answer 5

Hi bahushekh,

Please check the following article to see what to consider when you use the WebBrowser control  in the Microsoft Office 2003 programs and in earlier versions of Office.(At the bottom of that article)


Best regards,
Alex Liang

Search for  WebBrowser Control.



As above.  I like to know if the below work:

in the page, have 1 WebBrowser Control

1. Does it support Microsoft or google Map . 

2. How Do I embed a Html file in the project ? Embed it as Content file?

3. Base on (2).  Does WebBrowser Control support when the html file contain :

  Microsoft Map Control such as  VeMap ( ie map = new VEMap() Or the latest)

 or google Map Control similiar to VeMap Control of microsoft

4) How Do I pass data captured from Page to Html








I have a problem displaying MHT content in my webbrowser control (IE7/IE8)
It works if I open the .mht file from my harddisk like so:

myWebbrowserControl.Navigate "c:\test.mht" 

But I need to display the MHT content that is in a string variable.
So instead opening the MHT content from harddisk I need to display the MHT from a string.

The MHT string looks like this :

From: <saved with Windows Internet Explorer 8>
Subject: Welcome to my website
Date: Sat, 14 Aug 2010 22:43:27 +0200
MIME-Version: 1.0
Content-Type: multipart/related;
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5931

This is a multi-part message in MIME format.

Content-Type: text/html;
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.mywebsite.com

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns=3D"http://www.w3.org/TR/REC-html40" xmlns:v =3D=20
"urn:schemas-microsoft-com:vml" xmlns:o =3D=20
"urn:schemas-microsoft-com:.....  (+base64)

I try to display the string like so :

myWebbrowserControl.Navigate "about:blank"
myWebbrowserControl.Document.Write testMHT 

This displays the source - but it doesnt render the MHT string.
 Thank you


I have a web browser control and have a page loaded in it lets say www.gmail.com.

I want to provide some custom functionality to my end user for example, I want my user to be able to right click the firstname, lastname textboxes and the create new account button. On right click, I want to show my custom context menu with some options and want to determine the type of control (button, textbox etc) user has clicked and also the name or id of that control.

Is that possible?





I have a simple webpage that starts an ActiveX control. Here’s the code:

<script language="JavaScript" type="text/javascript">
   try {
      document.write("<object classid='clsid:1D980DC8-9C45-11D3-9C5C-00A13234F0A2' id='myActiveX' name=' myActiveX'  width='0' height='0'></object>");
      var bReturn = myActiveX.StartControl();
   catch (e) {
      document.write('Failed<br>' + e.name + '<br>' + e.message);

This works well when I call this page directly from Internet Explorer on Windows XP, 7 & server 2003

I created a .NET form in Visual Studio, and added a .NET WebBrowser Control from the toolbox. I set the URL of the WebBrowser to call the same web page.

I complied it & ran the executable. This works well from Windows XP & server 2003, but fails in Windows 7. Here’s the JavaScript error message:

Object doesn't support this property or method

Why would the ActiveX control work when calling directly from Internet Explorer, but not from within a WebBrowser control in Windows 7?

Thanks for reading.


Hi, I've got an issue with my popup control and webbrowser.

<phone:WebBrowserBackground="Red"x:Name="wbAuth"IsScriptEnabled="True"ns:WebBrowserUtility.BindableSource="{Binding WebAddress,Mode=TwoWay}">                  

Screenshot of the problem1

The result is : background color of the webbrowser has the good position, but the content is aligned on the top left hand corner.

Is it a known bug, or am i doing something wrong ?


After I added several mouse & keyboard events handlers in WebBrowser.OnDocumentComplete event:

            HTMLDocumentEvents2_Event eventHelper = (HTMLDocumentEvents2_Event)Document;

            eventHelper.onclick += new HTMLDocumentEvents2_onclickEventHandler(OnMouseClick);
            eventHelper.onmousedown += new HTMLDocumentEvents2_onmousedownEventHandler(OnMouseLButtonDown);

mouse wheel scrolling, as well as Document.execCommand (e.g. Document.execCommand("SelectAll", false, null)), doesn't work anymore.

Whereas mouse wheel event succesfully fired:

        private bool OnMouseWheel(IHTMLEventObj pEvtObj)
            return true; // true will cause scroll


I am navigating to a website using a webbrowers control and I wish to automatically scroll the page after it is loaded.

I have used scrolltop , scrollleft commands as set out below but nothing seems to happen.

 WebBrowser1.Document.Body.ScrollTop = 100
 WebBrowser1.Document.Body.ScrollLeft = 200

I have placed the above commands in a command button and wait until the page has loaded before I press it and also in the

 WebBrowser1_DocumentCompleted sub


other commands such as



seem to work ok


some help is appreciated







Hi all, 

I have an XBAP that contains a WebBrowser control.  In the control I am loading an aspx page (SharePoint or SSRS)  that I need to print.  It prints but it only prints what is visible on the screeen.  I need it to print everything in the control that is visible and scrollable.  PrintDocument gives me a cast error.  Any ideas?  This is kind of urgent. 

Here is my code.

 PrintDialog dialog = new PrintDialog();

      dialog.PageRangeSelection = PageRangeSelection.AllPages;
      dialog.UserPageRangeEnabled = true;

      if (dialog.ShowDialog() == true)
        dialog.PrintVisual(MyBrowserControl, ""); 
        //dialog.PrintDocument((((IDocumentPaginatorSource)MyBrowserControl.Document).DocumentPaginator), "");





I looked all over the forum posts here and didn't see the answer to a question concerning iframes within the webbrowser control (there were similar issues however).

The forum has a classifieds section that allows members to post threads daily. I have a message that I like to send once every day to a forum and decided that it would be best to achieve this programmatically. However, I noticed in the visual basic 2008 webbrowser control, that it doesn't seem to automate the iFrames within the browser using the htmlelementcollection codes.

 Here is what the iframe looks like in the html format:

<TDclass=controlbar><TEXTAREAstyle="WIDTH: 500px; DISPLAY: none; HEIGHT: 350px"dir=ltrid=vB_Editor_001_textareatabIndex=1rows=10cols=60name=message></TEXTAREA><IFRAMEstyle="WIDTH: 500px; HEIGHT: 350px"id=vB_Editor_001_iframetabIndex=1></IFRAME></TD><TDclass=controlbar>

Can someone please show a code sample for the above html iframe elements using the webbrowser control to input text inside of the textarea using a textbox1.text to specify the text going into the iframe textarea (this is where my message goes obviously). I'm trying to get my message into the textarea as soon as the webbrowser control loads the page

Would appreciate the help.

Kind Regards



I have a dedicated UI thread (not the process main thread) that has a message loop and creates a window with the WebBrowser ActiveX control. When the main thread processes it should be able to update the webbrowser control in the other thread. However this fails, because the WebBrowser control runs in a STA and ATL's CAxHostWindow gives me an assert about invalid thread IDs.


I want to call this on the control:


The main thread is loading a bunch of DLLs and after each DLL has been loaded the webbrowser control should display some message. So thats why its sitting on a seperate thread to run interdependent from the main threads processing.


Any ideas how to access the control from another thread?



I'm writing an application that queries a web page for information. I'm using a WebBrowser control to access the page that contains the info I'm looking for because I need the application to log in to the website and navigate to the desired page.

My code:

    Dim wb As WebBrowser = New WebBrowser

    While wb.ReadyState <> WebBrowserReadyState.Complete
    End While

    ' Currently on the login page
    wb.Document.GetElementById("username").InnerText = "me"
    wb.Document.GetElementById("password").InnerText = "somepassword"

    ' After the login succeeds, the browser redirects
    ' to a page with a menu.
    While Not wb.Url.ToString = "http://somewebsite:80/user"
    End While

    ' The 16th link on the menu page takes us where we want
    ' to go.

    While Not Microsoft.VisualBasic.Left(wb.Url.ToString, 33) = "http://somewebsite:80/desiredpage"
    End While

    ' Save the HTML from the desired page to a variable for
    ' analysis elsewhere in the application
    WebPage = wb.DocumentText

When I was writing this code, I went to the menu page and counted (from 0) the number of hyperlinks there and found the one I need to be the 16th link (or 15th in the collection).

The problem is that when I try running this code, I keep getting an ArgumentOutOfRangeException:

 System.ArgumentOutOfRangeException was unhandled
  Message="Value of '15' is not valid for 'index'. 'index' should be between 0 and -1.
Parameter name: index"
       at System.Windows.Forms.HtmlElementCollection.get_Item(Int32 index)
       at WindowsApplication1.Form2.Form2_Load(Object sender, EventArgs e) in C:\Documents and Settings\lyoung\My Documents\Visual Studio 2005\Projects\RecordingMonitor\RecordingMonitor\Form2.vb:line 26
       at System.EventHandler.Invoke(Object sender, EventArgs e)
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

I know for a fact that it's going to the right page, because I created another form with a WebBrowser control and a button on it, and placed the above code into the button's event handler, and modified it to use WebBrowser1.

Most confusing of all is that this code worked earlier today, and all of yesterday after I'd written it.

Any thought? Something I'm missing?
Thanks for the help!



Not sure if this is the best place to post this question, but here we go.

I am using the webbrowser control on C# app. I am trying to use 2008 Express edition (just moved to it ) and Vista home edtion--sorry don't have $$$ to buy the expensive stuff. Hopefully my issue is not related to the free software.

Now, I try to load url with flash content in it through the webbrowser control. Yet, it simply doesn't work. I installed flash9 but it complains about not finding flash.ocx. Actually the app simply puts annoying "x" but when I close devstudio it informs about this.

I googled around a bunch of posts and tried a bunch of things but none of them work. Most of the posts I've read seemed old and/or geared towards XP.

I did a search for *.ocx on my computer (although flash 9 is installed because the iexplorer works fine) and did not find any file called alike.  I believed flash9 does not use these names anymore. Not sure though.

Anyway, I am sort of stuck. And wonder if anyone has had this problem and has a solution that is up to date.



Hi all,

I hope someone can help me out with some information on this.
My problem is as follows:

I load some html text into the webbrowser control with this code:

string bodyText = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled Document</title><body leftmargin=\"0\" rightmargin=\"0\" topmargin=\"0\" bottommargin=\"0\">";

   string container = "<table width=\"240\" border=\"1\">";

   container += "<tr><td>Test</td>";

   container += "</tr></table></body>";

   string completeDoc = bodyText + container;

   webBrowser1.DocumentText = completeDoc;


I can see the table just fine, but the problem is that even though the width of the table is 240px, it takes up the entire width of a 480 x 800 px screen. So somehow the webbrowser is displaying everything twice as large as it should be. Does anyone know if I am doing something wrong or how it can be resolved?

Any suggestions are very much appreciated!



Summary: I can't get scrollbars to appear in a web browser control on my device. Also the text is too large

I have a web browser control inside my app (.Net v2.0 / C# / Windows mobile 6.5). When I use that part of my app on the emulator I get scroll bars, on my device (an HD2) I don't. The text is also very large. Because of these issues there is no way for the user to scroll, even thought the html document I've loaded clearly goes off the bottom of the page.

Is this just my device - or a general problem? I've found a few other mentions people having a similar problem, around the web.

I've seen Microsoft have released a cab file for .Net 3.5 that is meant to address webbrowser control issues - two problems with this, I would much prefer to keep my app .Net 2.0 for compatibility with the majority of my users, and also don't want to have to rely on my users installing a hotfix or an upgrade to the framework.

I can't find a fix (for a managed code app). Surely for such a fundamental part of the framework (surely I'm not the first app writer to want to display a web page in-app!?) there must be ways to get it to show scrollbars / the correct text size?

Any help much appreciated. Thanks!




On WindowsCE 6.0 I have sometimes the problem that the page content gets all distorted during scrolling. Do I need to set a special flag to prevent this from happening? It does not refreshes large amounts of the page and overpaints others in a strange way.






I have some static HTML-pages which i loaded into IsolatedStorage. I used the example as described in http://msdn.microsoft.com/en-us/library/ff431811%28v=VS.92%29.aspx . This works fine but when i want to refresh the HTML-page after some editing i'm unable to delete files from isolatedstorage which i browsed with the webbrowsercontrol. Even if i'm not on that page. Files i didn't browse yet, can be deleted without any problem.The only solution is to stop and start the debugger again. Any ideas how to refresh those HTML-files without restarting the debugger?

The errormessage is:"An error occurred while accessing IsolatedStorage." The code is below.

Greetz Sivard

public static void SaveFilesToIsoStore()
            //These files must match what is included in the application package,
            //or BinaryStream.Dispose below will throw an exception.,
                XDocument xIsoFiles = XDocument.Load("IsolatedStorageFiles.xml");
                var IsoFiles = from IsoStorageFiles in xIsoFiles.Descendants("file")
                               select IsoStorageFiles.Value;

                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                    foreach (string IsoFile in IsoFiles)
                        //Remove existing file
                        if (isoStore.FileExists(IsoFile))
                            //try to delete the old version.
                            catch (Exception e)
                                string err = e.Message;
                        if (isoStore.FileExists(IsoFile) == false)
                            StreamResourceInfo sr = Application.GetResourceStream(new Uri(IsoFile, UriKind.Relative));
                            if (sr != null)
                                using (BinaryReader br = new BinaryReader(sr.Stream))
                                    byte[] data = br.ReadBytes((int)sr.Stream.Length);
                                    SaveToIsoStore(IsoFile, data);
            catch (Exception err)
                throw new Exception("Error in SaveFilesToIsoStore:" + err.Message, err);






I have the following code:-

var content = "Hello – Testing";


The webbrowser displays it as "Hello   Testing", doesn't shows this "–" character.

and desktop wpf webbrowser also doesn't displays it properly: "hello – testing".

Also i think there are some more character's which are not displayed properly by webbrowser control but other controls like TextBlock work fine.

Any Solution ?


In reference to: 

=========================================================================== == 
IProtectFocus Interface 
Provides a method that queries for permission to grab the focus.

Hosts of MSHTML and the Web Browser control should respond to a 
IServiceProvider::QueryService for SID_SProtectFocus.

=========================================================================== ==

Anyone know how I implement this in VB6?



I have a webbrowser control embedded in at tabsheet and navigated to a page. The browser control size is set to display only a small portion of the page which I scrolled to. I also disable the scroll bars. Still, even though the scroll bars are not visible, the user can grab the page with the mouse and still scroll it. Is there a way to prevent the user from scrolling the underlying page?



We have an application that embeds Internet Explorer to display a specific web site. On some workstations the application cannot display the site, instead it displays an error page.

On some of these workstations focusing the web browser control and pressing F5 fixes the problem, on some other workstations it does not.

We've captured the NavigateError event, but it reports only error codes 0 and 7.

Has anyone encountered a similar problem?




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure