Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

Archive for the ‘Silverlight’ Category

Credentials, SharePoint Client Object Model and Silverlight

with 4 comments

When using the SharePoint Client Object Model in Silverlight, you need to add references to the Client Object Model assemblies prepared for Silverlight:

These assemblies are located in the “14” hive: \14\TEMPLATE\LAYOUTS\ClientBin. Note that when using the Client Object Model in other application types you use the libraries located in the ISAPI folder in the “14” hive (Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll).

Before executing Client Object Model calls you need to get a ClientContext object through which calls can be made. When running in a Silverlight application you can do this so:

            ClientContext clientContext = ClientContext.Current;

However, “ClientContext.Current” is only initialized when the Silverlight application is running on a page in a SharePoint site. If you run the Silverlight application on a page in another web site “ClientContext.Current” returns NULL. Creating your own ClientContext object is described in this post – the ClientContext class has a “Credentials” property which can be set through creating a new “NetworkCredentials” object.

But here’s the rub – the Silverlight Client Object Model does not support the Credentials property. So it would seem that Silverlight applications using the Client Object Model can only run in SharePoint sites.

So what about adding references to Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll instead? Doing this causes an error stating that the assemblies have not been prepared for the Silverlight environment.

Written by Nick Grattan

May 20, 2010 at 8:01 am