A simple example of the Silverlight managed client model in SharePoint 2010

Source: Internet
Author: User
Tags object model silverlight

The Silverlight managed client model is the three client model launched by SHAREPOINT2010. NET managed "," ECMAScript "," sliverlight ", they are not very familiar with Silverlight, this is the first attempt to sliverlight, however, our main attempt is the client model call SharePoint, Rather than the capabilities of Silverlight.

First, we open vs2010 new project, select Silverlight–silverlight Application, select the. Net 3.5 Framework, enter the name of our project to determine, pop-up Silverlight new wizard, This we do not need to change what set, OK on it. We then added a reference to the client model support in Silverlight, located at: Two DLL files under Template\layouts\clientbin

Microsoft.SharePoint.Client.Silverlight.dll

Microsoft.SharePoint.Client.Silverlight.Runtime.dll

After adding the reference, we can write our Silverlight program, and my example is to read an item from a list through the Silverlight client model and then display it to the Silverlight Web Part. After trying out the 3 client object model that SharePoint2010 launched, I thought it was similar, read the Web, read the list, read the list item and then display it, and then read the data first through the load. Then executequeryasync the data request. Also, the way Silverlight is executed is asynchronous.

Compared to SharePoint2007, the new version of 2010 support for Silverlight has improved a lot, and we will compile the Silverlight program, The. xap file in Debug is uploaded to the document library, then the Silverlight Web Part is added, the link to the Silverlight file is entered and can be added to SharePoint, as shown in my example. Behind there are code for everyone's reference, the first use of Silverlight, deficiencies, welcome everyone to correct the point.

Web web;
  
List List;
  
ListItemCollection LISTC; private void Button1_Click (object sender, RoutedEventArgs e) {clientcontext context = new ClientContext (application
  
CONTEXT.CURRENT.URL); Web = context.
  
Web; List = web.
  
Lists.getbytitle ("myfirstlists");
  
Camlquery query = new Camlquery (); Query.
  
ViewXml = ""; LISTC = list.
  
GetItems (query); Context.
  
Load (LISTC); Context. Executequeryasync (New Clientrequestsucceededeventhandler (onsuccessed), New Clientrequestfailedeventhandler (
  
onfailed)); } private void onsuccessed (Object sender, Clientrequestsucceededeventargs args) {this.
  
Dispatcher.begininvoke (LoadData);
  
private void LoadData () {String str = ""; foreach (ListItem item2 in listc) {str = item2["Title"].
  
ToString () + "\ r \ n"; } Label1.
  
Content = str; } private void Onfailed (Object sender, Clientrequestfailedeventargs args) {this.
  
Dispatcher.begininvoke (Delegate () {MessageBox.Show ("Failed");}); }

Author: Lin Yu

Source: Http://www.cnblogs.com/jianyus

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.