Silverlight works on client side, so it's not possible to add SharePoint libraries in Silverlight project. But we have a way that we can access SharePoint data and show it up in Silverlight in SharePoint site.
We have a requirement where we need to pull data from the SharePoint libraries and lists and show the data in Silverlight. Here i will explain a scenario where we can pull the images from image library and show it in Silverlight.
Follow the steps below to do this.
Get data from SharePoint library and make it in the form of XML.
- Go to the page where we want to show the Silverlight module on the site or create a new page.
- Open the page in SharePoint designer.
- Add a data view web part to the page some where in web part zone.
- Select the data source library from Task Pane menu.
- Select the library/list from the data source library where your images are present.
- Click on the library and select Show Data.
- Select the columns, which refer the Title, Image Path etc you want to show in Silverlight from Data Source details task pane.
- Select the option Insert select fields as "Multiple item view". So now our data view web part is filled with the data. [If you want apply some properties like show images in asc order etc..]
- After selected the columns, apply a filter to get only images from the library/lists. we can do this by selecting the filters option from the data view web part.
- Here, select the image title or url column in the field name, in comparison select contains and here enter valid formats Silverlight allows in the value field.
- Save the page and open it in the browser [IE].
- Till now what we did is, we are getting the data from the SharePoint library/Lists and showing up it in the data view web part and it renders as a table.
- Now, we need to change the XSLT of the data view web part to get the table format of data as the XML format. We have XSLT, so we can easily do that.
- Add the below XSLT code to the data view web part by going to edit for the web part and modify settings --> XSL editor.
- Remove text in the editor and add this code.
- If you observe i am pulling some values from the data view and making xml.
- Now, when you save the web part and see the page, you can't see anything in the data view web part, because now your data is in the format of xml.
- You can see this by doing view source and search for "
- We are done with part 1 now. i.e. getting data from SharePoint library. Now we will move to second part.
At this point, we got the xml i.e. xml is on the page, now we need to read the xml from the page in the silverlight project and display the images as we want by applying animations, styles etc..
You can see the part 2 here.