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/