
410
❘
CHAPTER 14 SILVERLIGHT AND SHAREPOINT INTEGRATION
using System.Windows.Resources;
namespace Contacts
{
public class LoadClientOM
{
private Action action;
public LoadClientOM(Action action)
{
this.action = action;
WebClient client = new WebClient();
client.OpenReadCompleted +=
new OpenReadCompletedEventHandler(ReadCompleted);
client.OpenReadAsync
(new Uri(“/_layouts/clientbin/Microsoft.SharePoint.Client.xap”,
UriKind.Relative));
}
void ReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
Stream assemblyStream;
AssemblyPart assemblyPart;
assemblyStream = Application.GetResourceStream(new
StreamResourceInfo(e.Result, “application/binary”),
new Uri(“Microsoft.SharePoint.Client.Silverlight.Runtime.dll”,
UriKind.Relative)).Stream;
assemblyPart = new AssemblyPart();
Assembly b = assemblyPart.Load(assemblyStream);
assemblyStream = Application.GetResourceStream(new
StreamResourceInfo(e.Result, “application/binary”),
new Uri(“Microsoft.SharePoint.Client.Silverlight.dll”, UriKind.Relative)).Stream;
assemblyPart = new AssemblyPart();
Assembly a = assemblyPart.Load(assemblyStream);
//Call back on the passed delegate
if (action != null)
{
action();
}
}
}
}
The LoadClientOM constructor takes one parameter, the callback method to call after the
assemblies have been loaded. Next, the constructor uses the
WebClient class to download the
Microsoft.SharePoint.Client.xap asynchronously ...