Create Silverlight 1.1 applications for SharePoint with VS2008
Title says it all :-) My plan is to create small walkthrough how you can create your own Silverlight 1.1 application with Visual Studio 2008 and then run it in SharePoint. And I don't want to install a lot of stuff to my SharePoint environment so I'll just create simple web part to host the Silverlight application. All development work will be done outside SharePoint environment.
If you're new to Silverlight then I suggest you start by looking at least silverlight.net and cool Coding4Fun Silverlight 8-Ball example. The first link is starting point for Silverlight development and the second one is really cool sample that shows how can you create 8-Ball game with Silverlight.
Now you know something about Silverlight :-) So we can get started with my example.
I have VS2008 running on my Vista and I have downloaded and installed Microsoft Silverlight 1.1 Tools Alpha for Visual Studio 2008 to help me developing Silverlight applications. It has new project template that has all the necessary stuff already set up to build Silverlight 1.1 application. I also have SharePoint running in my Virtual PC and it's configured so that I can connect to it directly from my host machine (i.e. http://demo1:1000 in my host IE connects to the virtualized SharePoint).
At first I'll modify SharePoint so that I can host my new applications in there. Let's add few folders under _LAYOUTS:
ClientBin is folder that will contain all Silverlight client .dll files (=if you build your Silverlight project you automatically get ClientBin under your project folder which contains your projects client assemblies).
Silverlight folder is used to store .xaml files (=Silverlight pages). I also need to change settings for both of them in order make things work. First I'll change ClientBin settings:
Set only Read access and also set Execute permissions to None:
Then I'll add .dll to allowed mime types (and .pdb for future debugging purposes :-):
Then I'll change the Silverlight folders settings to support .xaml extension:
Now SharePoint is set up... but let's create web part that will actually host the Silverlight application in our page. Here's the code for that:
My web part uses Silverlight.js and SilverlightStarter.js files. SilverLight.js is the same file that is included at the project when you create Silverlight 1.1 project in VS. SilverlightStarter.js is almost copy paste from that project template too but I have just modified it a little bit to support sending XAML file as parameter:
And if you checkout my web part code on line 35 you actually notice that I'll just pass on the XAML file that has been set in web part properties:
Now we just need to add some Silverlight stuff and we're done. So here is the content of the Page.xaml (=THE application :-):
And my code behind Page.xaml.cs contains following code:
Now you're probably eager to know what our application actually does :-) Here is our application just after request:
And if user clicks the rectangle...
If user clicks the text...
Now we have working development environment so that we could build ant test Silverlight 1.1 applications and host them in SharePoint. Here are the steps so that you can (try :-) to do it yourself.
1) Create new Silverlight project in VS2008
2) Code :-)
3) Build your solution
4) Copy contents of ClientBin\*.* to the SharePoint _LAYOUTS\ClientBin folder
5) Copy *.xaml files from your project to the SharePoint Silverlight folder (Note: you need to verify correct path in x:Class! See my Page.xaml and line 5 in source)
6) Create page that uses Silverlight web part and select your newly created XAML file
Here was my small intro to Silverlight 1.1 with SharePoint. In this example I just used static .xaml files sitting in file system in order to make everything as simple as possible... I just wanted to demo how you can start experimenting with this combination. This can be extended and improved in many different ways and I'll probably come back to those in my future posts.
Anyways... Happy hacking!