2014-02-15 57 views
0

我使用Nuget將HTML Agility Pack(HAP)添加到了我的解決方案中。我的解決方案使用Silverlight 5.我可以從「使用HtmlAgilityPack;」調用一些函數但有些功能我不能打電話。我需要通過下面的代碼行獲取URL的內容:如何在Lightswitch 2013桌面應用程序中使用HTML Agility Pack

string Url = "http://google.com.vn"; // this line is okay 
HtmlWeb web = new HtmlWeb(); // this line is okay 
HtmlDocument doc = web.Load(Url); // but this line is highlighted with an error 'Error HtmlAgilityPack.HtmlWeb' does not contain a definition for 'Load' and no extension method 'Load' accepting a first argument of type 'HtmlAgilityPack.HtmlWeb' could be found (are you missing a using directive or an assembly reference?)' 
+0

嘗試'LoadAsync()'和'LoadCompleted'。 – CodeCaster

+0

LoadAsync沒有參數LoadCompleted。我試過了 –

回答

0

我解決我的問題

using System; 
using System.Linq; 
using System.IO; 
using System.IO.IsolatedStorage; 
using System.Collections.Generic; 
using Microsoft.LightSwitch; 
using Microsoft.LightSwitch.Framework.Client; 
using Microsoft.LightSwitch.Presentation; 
using Microsoft.LightSwitch.Presentation.Extensions; 
using System.Windows; 
using Microsoft.LightSwitch.Threading; 
using HtmlAgilityPack; 

namespace LightSwitchApplication 
{ 
public partial class Table1ItemsListDetail 
{ 
    partial void Method_CanExecute(ref bool result) 
    { 

     // Write your code here. 


    } 

    partial void Method_Execute() 
    { 

      var wc = new HtmlWeb(); 
      // string url = "http://www.nu.nl/feeds/rss/algemeen.rss"; 

      wc.LoadAsync("http://google.com"); 

      wc.LoadCompleted += new EventHandler<HtmlDocumentLoadCompleted>(DownloadCompleted); 
      //wc. 
     // 

    } 
    void DownloadCompleted(object sender, HtmlDocumentLoadCompleted e) 
    { 
     if (e.Error == null) 
     { 
      HtmlDocument doc = e.Document; 
      if (doc != null) 
      { 
       Dispatchers.Main.BeginInvoke(() => 
       { 
        MessageBox.Show(doc.DocumentNode.Element("html").InnerHtml); 

       }); 
      } 
     } 
    } 

} 

}

相關問題