get html content of a page with Silverlight

Posted by Yustme on Stack Overflow See other posts from Stack Overflow or by Yustme
Published on 2010-05-03T10:44:57Z Indexed on 2010/05/03 10:48 UTC
Read the original article Hit count: 291

Filed under:
|
|
|
|

Hi,

I'm trying to get the html content of a page using silverlight. Webresponse and request classes don't work in silverlight.

I did some googling and I found something. This is what i tried:

public partial class MainPage : UserControl
 {
  string result;
  WebClient client;

  public MainPage()
  {
   InitializeComponent();
   this.result = string.Empty;
   this.client = new WebClient();
   this.client.DownloadStringCompleted += ClientDownloadStringCompleted;
  }

  private void btn1_Click(object sender, RoutedEventArgs e)
  {
   string url = "http://www.nu.nl/feeds/rss/algemeen.rss";

   this.client.DownloadStringAsync(new Uri(url, UriKind.Absolute));

   if (this.result != string.Empty && this.result != null)
   {
    this.txbSummery.Text = this.result;
   }
  }

  private void ClientDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
  {
   this.result = e.Result;
   //handle the response.
  }
 }

It gives me a runtime error after pressing the button:

Microsoft JScript runtime error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary() at System.Net.DownloadStringCompletedEventArgs.get_Result() at JWTG.MainPage.ClientDownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e) at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)

I've tried numerous things but all failed.

What am i missing? Or does anyone know how i could achieve this in a different way?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about html