然后,我们把上一篇的代码复制过来,看看能不能工作
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes;
using Microsoft.SharePoint.Client;
namespace SilverlightApplication3 { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); Loaded += new RoutedEventHandler(MainPage_Loaded); }
void MainPage_Loaded(object sender, RoutedEventArgs e) {
var url = \
using (ClientContext ctx = new ClientContext(url)) { //ctx.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; Web web = ctx.Web; ctx.Load(web); ctx.Load(web.Lists); ctx.Load(web, w => w.Lists.Where(l => l.Title == \ ctx.ExecuteQuery();
List list = web.Lists[0]; CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = \ Name='Age' />
ListItemCollection collListItem = list.GetItems(camlQuery);
ctx.Load(collListItem); ctx.ExecuteQuery();
var emps = collListItem.Select(i => new Employee() { FirstName = i[\ LastName = i[\ }); EmployeeList.ItemsSource = emps;
} } }
public class Employee { public string FirstName { get; set; } public string LastName { get; set; } } } 【注意】以上代码几乎和之前在Console里面一模一样
按下F5键运行,我们却收到了一个错误
查看原图(大图)
这其实是我们预见到的错误,之前我就说到过了,Silverlight程序所有的外部资源访问都要求是异步进行的。那就动手改一下吧
首先为了做得更加完善些,我们在布局方面做了一下小的调整添加了错误消息提示的功能