none
axWebBrowser - catch "page cannot be displayed"

    Question

  • Hello,

    I have a vs.net 05 c# application in which I am using an axWebBrowser control to display Visio diagrams (*.vsd). (If the free Visio Viewer provided by Microsoft is installed on a computer, you are able to view Visio diagrams in Internet Explorer).
     
    Of course, not all my users have the Visio Viewer installed, so I want to show a message providing more info when I detect this. Currently, the axWebBrowser redirects to the system "The page cannot be displayed" error page. My problem is that I don't know how to trap this event in order to provide a custom message instead. Can anyone help, please?

    Wednesday, October 11, 2006 11:23 AM

Answers

  • usually when you load a webbrowser there is nothing being displayed at all, just a blank page. but if you are saying that this page would appear when say, they dont have a specific component installed then I guess you can go into the document_completed event and check what the page text is (document.body??) and if it is "page cannot be displayed" then provide your custom error message there. Is this what you maybe after?

    I guess you can also look at implementing the navigated event to check the url that it is being navigated to (check to see what the url of the page cannot be displayed is) then handle it but I still think the page would be displayed like this even without changing the url address. It's an interesting one.

    if you are just wanting to view the specific file, when navigating, check the url - if it ends in the extension of the visio file format, check the system to see if the app is installed (look for the path to the viewer) then if it does not exist, tell the user this and cancel the navigation. Maybe not the best way but it is an option

    Friday, October 13, 2006 9:56 AM

All replies

  • You can do a check when the page loads.  You can check to see if the directory of the application they need to install exists and then display and error message and navigate them to a custom error page you create.

    //Check the directory
    if (System.IO.Directory.Exists(path of directory to check)
    {
         //...
    }
    else
    {
         MessageBox.Show("You need blah installed blah blah blah", "Error");
         this.webBrowser1.Navigate("your custom error page address/url");
    }

    Now you're going to ask yourself, what if they did not install it in the default directory?  Use the registry.  Almost all applications use the registry to store some kind of data.  The most common being a application install path for future reference.

    if (Registry.GetValue(blah blah blah))
    {
         //...
    }
    else
    {
         MessageBox.Show("You need blah installed blah blah blah", "Error");
         this.webBrowser1.Navigate("your custom error page address/url");
    }

    I hope this gives you some idea of how you can achieve your goal.
    Wednesday, October 11, 2006 1:30 PM
  • Thanks for the suggestion. But I feel that using the registry is not the most elegant solution for this. What I want is to display something else to my users instead of the "Page cannot be displayed" system page that they're seeing. I don't want to tell them they need to install Visio Viewer in a situation when that error page might not be even displayed to them (EG: when they have the full Visio installed). So, what I'm trying to do is to catch that redirect in the webbrowser control and handle it by myself in my application.
    Friday, October 13, 2006 9:03 AM
  • usually when you load a webbrowser there is nothing being displayed at all, just a blank page. but if you are saying that this page would appear when say, they dont have a specific component installed then I guess you can go into the document_completed event and check what the page text is (document.body??) and if it is "page cannot be displayed" then provide your custom error message there. Is this what you maybe after?

    I guess you can also look at implementing the navigated event to check the url that it is being navigated to (check to see what the url of the page cannot be displayed is) then handle it but I still think the page would be displayed like this even without changing the url address. It's an interesting one.

    if you are just wanting to view the specific file, when navigating, check the url - if it ends in the extension of the visio file format, check the system to see if the app is installed (look for the path to the viewer) then if it does not exist, tell the user this and cancel the navigation. Maybe not the best way but it is an option

    Friday, October 13, 2006 9:56 AM