Elczar Adame's Shared Points on SharePoint

Archive for May, 2011

SharePoint List Items in a Silverlight DataGrid


Do you have a requirement to bring your SharePoint list items in a Silverlight datagrid? The sample code below might help you.

 1: String listname = "YourCustomList";
 2: String webfullurl = "http://yourspsite/";
 3: ClientContext clientcontext;
 4: ListItemCollection listitemcollection;
 5:  
 6: private void GetItems(string Status)
 7: {
 8:    using (ClientContext clientcontext = new 
ClientContext(webfullurl))
 9:    {
 10:       Web web = clientcontext.Web;
 11:       ListCollection listcollection = web.Lists;
 12:       List list = clientcontext.Web.Lists.GetByTitle
(listname);
 13:       clientcontext.Load(list);
 14:  
 15:       CamlQuery camlquery = new CamlQuery();
 16:       camlquery.ViewXml = "<View><Query><OrderBy>
<FieldRef Name='Title'/></OrderBy></Query></View>";
 17:       listitemcollection = list.GetItems(camlquery);
 18:       clientcontext.Load(listitemcollection);
 19:  
 20:       clientcontext.ExecuteQueryAsync
(OnQuerySucceeded, OnQueryFailed);
 21:    }
 22: }
 23:  
 24: private void OnQuerySucceeded(object sender, 
ClientRequestSucceededEventArgs args)
 25: {
 26:    UpdateUserInterface updateuserinterface = 
FillDataGrid;
 27:    this.Dispatcher.BeginInvoke(updateuserinterface);
 28: }
 29:  
 30: private void FillDataGrid()
 31: {
 32:    List<YourListItems> yourlistitems = new 
List<YourListItems>();
 33:    foreach (ListItem listitem in listitemcollection)
 34:    {
 35:       yourlistitems.Add(new YourListItem()
 36:       {
 37:          Title = listitem["Title"].ToString()
 38:        });
 39:    }
 40:  
 41:    GridOpenPositions.ItemsSource = yourlistitems;
 42: }
 43:  
 44: private void OnQueryFailed(object sender, 
ClientRequestFailedEventArgs args)
 45: {
 46:    HtmlPage.Window.Alert("Request failed. " + 
args.Message + "\n" + args.StackTrace);
 47: }
 48:  
 49: private delegate void UpdateUserInterface();
 50:  
 51: public class YourListItems
 52: {
 53:    public string Title { get; set; }
 54: }
Digg This
Advertisements

SP1 for SharePoint 2010 and Office 2010 Unveiled


Yes, you are right! Microsoft has already revealed the release of SP1 for SharePoint 2010 and Office 2010 at the end of June 2011.

On the Microsoft SharePoint Team Blog, Bill Baer, Senior Technical Product Manager, Microsoft Corporation, has provided some of the improvements we could expect. The SP1, moreover, will bring us several remarkable updates across client suites. The Microsoft Office Sustained Engineering and Release Team provides us the details.

Digg This

Tag Cloud