locked
Get HtmlDocument RRS feed

  • Question

  • With the following setup I am getting a null HtmlDocument.  How can I get the current HtmlDocument in my WebBrowser control?

    C#...

    using System.Windows; using System.Windows.Forms; namespace WpfApplication1 { public partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } private void Button_Click(object sender, System.Windows.RoutedEventArgs e) { myWeb.Navigate(this.linkText.Text); } private void next() { HtmlDocument doc = myWeb.Document as HtmlDocument; if (doc != null) System.Windows.MessageBox.Show("document found"); else System.Windows.MessageBox.Show("doc is null"); } private void nextClick(object sender, System.Windows.RoutedEventArgs e) { next(); } } }

     

    XAML...

    <Grid x:Name="LayoutRoot">
    		<Grid x:Name="myGrid" Margin="0,0,199,0">
    			<WebBrowser x:Name="myWeb"/></Grid>
    		<TextBlock x:Name="linkText" HorizontalAlignment="Right" TextWrapping="Wrap" Text="http://www.google.com" VerticalAlignment="Top" Margin="0,8,8,0" Width="191" Height="40.96"/>
    		<Button Content="Get Page" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Margin="0,75.04,8,0" Click="Button_Click"/>
    		<Button Content="Next" HorizontalAlignment="Right" VerticalAlignment="Top" Width="75" Margin="0,101,8,0" Click="nextClick"/>
    	</Grid>

    Thanks in advance for your help.

    ~Christine


    My Gallery

    Friday, May 4, 2012 8:05 PM

Answers

  • Try the following code:

    dynamic doc = myWeb.Document;
                if (doc != null)
                    System.Windows.MessageBox.Show("document found");
                else
                    System.Windows.MessageBox.Show("doc is null");


    Need translation help? I translate from English to Japanese and vice versa. Please feel free to contact me for your translation needs. 日英・英日翻訳依頼を受け付けています。 お気軽にご相談下さい。(Ldiary.com)

    Friday, May 4, 2012 9:05 PM

All replies

  • Try the following code:

    dynamic doc = myWeb.Document;
                if (doc != null)
                    System.Windows.MessageBox.Show("document found");
                else
                    System.Windows.MessageBox.Show("doc is null");


    Need translation help? I translate from English to Japanese and vice versa. Please feel free to contact me for your translation needs. 日英・英日翻訳依頼を受け付けています。 お気軽にご相談下さい。(Ldiary.com)

    Friday, May 4, 2012 9:05 PM
  • You're a Star!

    Thanks a bunch!

    ~Christine


    My Gallery

    Friday, May 4, 2012 9:13 PM