SharePoint 2013 Silverlight中使用Net用戶端物件模型

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

  1、建立Silverlight時,選擇Silverlight 4,不要選擇版本5,試了很久版本5都調用不了,自己也不知道什麼原因,Google也沒找到答案,後來嘗試版本4,可以調用;

  至於Host the Silverlight application是否勾選沒有影響;

  2、Silverlight中使用用戶端指令碼,和Net中不一樣,要添加下面兩個引用;

  3、兩個需要的引用,在伺服器上位置為C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\ClientBin,如:

  4、然後在Silverlight的cs檔案中添加引用,如下:

  using Microsoft.SharePoint.Client;

  然後添加讀取List的代碼,如下:

public string url = "http://server:80";Web web;List list;ListItemCollection itemColl;string listName = "Silverlight";string camlStr = "";private void btn_ShowMessage_Click(object sender, RoutedEventArgs e){ getdata();}public void getdata(){ try { ClientContext context = new ClientContext(url); web = context.Web; list = web.Lists.GetByTitle(listName); CamlQuery query = new CamlQuery(); query.ViewXml = camlStr; itemColl = list.GetItems(query); context.Load(itemColl); context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnSuccessed), new ClientRequestFailedEventHandler(OnFailed)); } catch (Exception ex) { MessageBox.Show(ex.Message); }}private void OnSuccessed(Object sender, ClientRequestSucceededEventArgs args){ this.Dispatcher.BeginInvoke(LoadData);}private void LoadData(){ String data = string.Empty; foreach (ListItem item in itemColl) { data += item["Title"].ToString() + "\r\n"; } lb_Message.Content = data;}private void OnFailed(Object sender, ClientRequestFailedEventArgs args){ this.Dispatcher.BeginInvoke(delegate() { MessageBox.Show("Get Data Failed"); });}

  5、前台頁面添加Silverlight展示WebPart,添加完畢如:

  6、點擊ShowMessage,執行用戶端物件模型的方法,結果如:

總 結

  自己對於Silverlight不是很熟悉,只是小有瞭解SharePoint,所以有問題之處還請大家指正。嘗試了很多次,才發現如何能在Silverlight中使用SharePoint用戶端物件模型,希望分享給有需要的人,給大家一個參考吧。

  好了,就到這裡,休息。。休息一下。。

SharePoint 2013 Silverlight中使用Net用戶端物件模型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.