Wednesday, November 9, 2011

How to Deploy Silverlight XAP file to a Document Library

Okay, so you have developed your silverlight application in SharePoint and you now want to deploy it. So you take your XAP file add it your document library and then reference it from your Silverlight Web Part right? Seems kind of like a long process, if you also had to deploy a whole bunch of web part with.

So we can make it simple by deploying our XAP with the rest of the web parts, lists, etc. All you need to do is follow a few simple steps and your XAP file will be deployed to your site with the rest of your customisations.

Step 1
Add a new module to your solution

Step 2

Right Click on the module you have just added and select properties.
Look for "Project Output References" click on the elipsis and click add.
Set the deployment type to a "ElementFile" and select your project name

Click ok and you should notice your Elements.xml has been modified to something like the following:

You can now proceed to change it to look like the below:


Happy coding guys I hope this helps make your deployment alot simpler.

Inserting SharePoint List item using Silverlight Object Model

If you finally came over to the dark side and embraced Silverlight in SharePoint you should familarize yourself with the Client API for Silverlight, I have mentioned in a previous post how to reference these assemblies.

If you want to be more adventourous and insert list items using the Client API you can use the following code:
ClientContext context = ClientContext.Current;

List oList = context.Web.Lists.GetByTitle("HelloWorldList");

ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "Hello World";

context.Load(oList, list => list.Title);
context.ExecuteQueryAsync(OnSuccess, OnFailed);
The above method is done assyncrously so you will have a call back which means if the insert is success code sample A if it is unsuccessful run code sample B, see below:
private void onSuccess(object sender, ClientRequestSucceededEventArgs args)
   Deployment.Current.Dispatcher.BeginInvoke(() =>
 private void onFailed(object sender, ClientRequestFailedEventArgsargs)
   Deployment.Current.Dispatcher.BeginInvoke(() =>
As you know these operations are done assyncronously so simply put we have to get the attention of the UI thread to perform our success or failure action.
Happy coding :-)

Getting started with SharePoint 2010 Silverlight Client Object Model

Getting started with SharePoint 2010 Silverlight Client Object Model -

When you want to use the Silverlight Object Model the first thing we are going to is add a reference to silverlight assemblies:
  • Microsoft.SharePoint.Client.Silverlight.dll
  • Microsoft.SharePoint.Client.Silverlight.Runtime.dll
These assemblies can be found at the following location :
  • C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin
Then in your code just reference the assembly and you should be good to go as shown below:
  • using Microsoft.SharePoint.Client; 
    So happy coding guys, hope you enjoy the Silverlight Client Object Model