Archive

Posts Tagged ‘Silverlight’

Code samples from: – SharePoint Conference 2009, "Advanced Development for Silverlight 3 in SharePoint 2010"

Code samples from:
- SharePoint Conference 2009, "Advanced Development for Silverlight 3 in SharePoint 2010"
- MSDN Webcast Feb 2010, "Developing Rich Solutions in Silverlight for SharePoint 2010"
- ReadMe.docx

This release includes a recording of the MSDN Webcast,

“Developing Rich Solutions in Silverlight for SharePoint 2010”

along with the code shown in the webcast. These are updates of the same solutions shown at SharePoint Conference 2009 in the talk, “Advanced Development for Silverlight 3 in SharePoint 2010”; this Code Gallery release will serve to provide the sample code from both talks.

The code samples are as follows:

SharePoint and Silverlight from Scratch

This walkthrough was presented only in the webcast to show how to get stared developing in Silverlight for SharePoint 2010. The sample includes only the snippets (in Visual Studio snippet format); it will be necessary to watch the webcast to see how to use them.

Picture View Web Part

This is a Silverlight web part that shows a slide show of images stored in a SharePoint picture library. This demonstrates how to use the HTML bridge to reduce the number of round-trips to the server. In this case, the server side web part passes the URL’s of the pictures to Silverlight in a hidden form field, removing the need for the Silverlight application to query the server for the list of pictures.

Paged List View Web Part

This is a Silverlight web part that shows a grid of data from a SharePoint list. It allows paging, sorting and filtering, and only loads an n-row page at a time to allow viewing a large data set without downloading the whole thing to Silverlight. In addition to loading the first “page” of data in a hidden field (like the Picture View web part) , it obtains additional content using ADO.NET Data Services and SharePoint’s new RESTful interface.
NOTE this release does not include the target list, and the sample will not run without it. A future release may include a matching list definition with sample data.

Video Field Control

This adds a Video field to SharePoint, using Silverlight applications to view and select the video. The actual field simply stores the URL of the video. The Silverlight display application is very simple, and just plays the video based on this URL. The selector application is more interesting as it uses the client object model to provide a simple browsing and preview feature in which the user can select a site, library and video to be shown.

Connected Silverlight Web Parts

This sample includes a pair of web parts – a source and target. When connected via the web browser, text entered into the source web part will appear on all targets as it is typed. This shows how to use SharePoint’s web part connection mechanism – which runs on the server side – as a broker to connect the Silverlight applications. The Silverlight applications communicate using the new Silverlight 3.0 Local Messaging API.

 

Extracted from

http://code.msdn.microsoft.com/SP2010Silverlight

February 11th, 2010 Neal McFee No comments

Walkthrough 6: Extending the SharePoint 2010 UI with Silverlight

Exercise Duration

: 20 minutes

Exercise Overview

This example shows how to create a Silverlight Application that uses the SharePoint Client Object model to render SharePoint list data. It also shows how to host that Silverlight Application in the Silverlight web part on SharePoint.

Feature Overview

The Silverlight Web Part allows developers and users to easily add Silverlight applications (*.XAP) to SharePoint sites. Client Object Model can be used in Silverlight to access SharePoint programmatically.

Task 1: Create a Silverlight Application for the SharePoint Client Object Model.

1.

Open Visual Studio 2010 from the Start | Programs | Visual Studio 2010 menu.

2.

Create a new project by using File | New Project.

3.

Pick the Visual C# | Silverlight templates.

4. From the Visual C# | Silverlight templates select the Silverlight Application

template.

5. Use SPSilverlightExample as the name.

6. Set the location to be C:\SPHOLs

.

7. Press OK to create the project.

image

8.

When the New Silverlight Application dialog appears, accept all the defaults by pressing OK.

image

9.

Right-click on the SPSilverlightExample project in the Solution Explorer and select Add Reference.

10.

Go to the Browse tab in the Add Reference dialog, and add a reference to the two assemblies from the specified location:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin\

The file names are: Microsoft.SharePoint.Client.Silverlight.dll and Microsoft.SharePoint.Client.Silverlight.Runtime.dll.

image

Task 2: Write code to access and render SharePoint List Data

1.

Open the Toolbox and expand Silverlight Controls.

2.

Drag a DataGrid control onto the Silverlight Designer.

image

3.

In the Solution Explorer right-click on Page.xaml and select View Code.

4.

Inside the Page.xaml.cs add the following using statement at the top of the file:

using

Microsoft.SharePoint.Client;

5. Add the following class before the Page class:

public class Project

{

   public String Title { get; set; }

   public DateTime DueDate { get; set; }

   public String Description { get; set; }

}

6. Add the following member to the Page class itself:

ListItemCollection _projectItems;

7. Add the following code to the Page Constructor

var context = new

ClientContext(ApplicationContext.Current.Url);

context.Load(context.Web);

var projects = context.Web.Lists.GetByTitle(“Projects”

);

context.Load(Projects);

var query = new

Microsoft.SharePoint.Client.CamlQuery();

var strQuery = “<View><Query><Where><Gt>”

+

   “<FieldRef Name=’Due_x0020_Date’ />”

+

   “<Value Type=’DateTime’>2008-01-1T00:00:00Z</Value>”

+

   “</Gt></Where></Query><ViewFields>”

+

   “<FieldRef Name=\”Title\” /><FieldRef Name=\”Description\” />”

+

  “<FieldRef Name=\”Due_x0020_Date\” />”

+

   “</ViewFields></View>”

;

query.ViewXml =

strQuery;

_projectItems = projects.

GetItems(query);

context.

Load(_projectItems);

context.ExecuteQueryAsync(OnRequestSucceeded, null

);

8.

Add the following code inside of the Page class after the constructor:

private void

OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)

{

   // this is not called on the UI thread

   Dispatcher.BeginInvoke(BindData);

}

private void

BindData()

{

           var list = new List<Project>();

           foreach (var li in _projectItems)

           {

               list.Add(new Project

               {

                   Title = li["Title"].ToString(),

                   DueDate =         Convert.ToDateTime(li["Due_x0020_Date"].ToString()),

                  Description = li["Description"].ToString()

               });

           }

           dataGrid1.DataContext = list;}

This code initializes the SharePoint Silverlight client object model context (ClientContext). It then gets a reference to the Projects list. Runs a simple CAML query against the list to pull all projects with a duedate greater than 1/1/2008. The results are converted into a list of Projects and bound to the Silverlight DataGrid control.

Task 3: Deploy and Test using the SharePoint Silverlight web part.

To deploy the solution to SharePoint the resulting .xap file needs to be in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder.

1.

Right click on your project and select properties and select the Build tab.

2.

Change the output path to the following: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin.

image

3. Build the solution and fix any typos that may have occurred

.

4.

Add the SharePoint Silverlight web part to a web part page:

Click the Edit button to put the page in edit mode.

Click Insert

Click Web Part

Click Authoring

Click Silverlight Web Part

Click Add

5.

When prompted type in: /_layouts/ClientBin/SPSilverlightExample.xap

image

The rendered web part looks like this:

image

Exercise Summary

In this walkthrough you built a Silverlight application that accesses SharePoint lists using the Client Object Model.

February 10th, 2010 Neal McFee 1 comment