Testing the Web Method
Now that you've added the code to your solution, you'll want to test out the Service to make sure it works. To test out the code 1. Change the SPSite value to your own SharePoint default site if you didn't use the GetContextSite method and add a list called Survey to SharePoint with two fields called Question and Answer. To do this, navigate to your SharePoint site, click ''View All Site Content,'' and click Create. Under Custom Lists, click ''Custom List,'' and provide a name and description...
Listing Core field type class continued
using Microsoft.SharePoint.Security Guid 1b6 64652-3 97c-4cb6-93 5c-1c088694afe4 public class LikertScaleField SPFieldText public LikertScaleField SPFieldCollection fields, string fieldName base fields, fieldName public LikertScaleField SPFieldCollection fields, string typeName, string displayName base fields, typeName, displayName public override BaseFieldControl FieldRenderingControl ObjectModel true BaseFieldControl fieldControl new LikertScaleFieldControl fieldControl.FieldName...
Creating a Basic Master Page
The easiest way to create this basic or minimal master page as it is called in Help documentation and around the Web is to find an existing one as a starting point. Start with the MiniMaster.master found in the MSDN documentation site. You can find this sample at This is a basic page with no formatting. There are many other good minimal master pages out there that you should use when you get ready to do this on your production site. But for now, this simplicity will allow you to focus on the...
Troubleshooting Tips
As you know, development is not always without some degree of troubleshooting, so here are a few things to keep an eye on as you integrate your Silverlight applications with SharePoint If you get ambiguous network errors when loading media, this is often because the deployed assembly cannot find the media. Make sure that the media loads properly in the Silverlight application first in the test environment. If it does, then, when deployed, the Silverlight application is not finding the media....
C Mgu
private void UpdateTheOtherControl int value List lt string gt SLRatingControls GetSLRatingsControlsList iterate through all of the controls updating the Rating value foreach string SLCtrl in SLRatingControls ScriptObject Content ScriptObject otherControl value
C Wpm
protected override void OnLoad EventArgs e ScriptManager scriptManager scriptManager new ScriptManager this.Controls.Add scriptManager protected override void CreateChildControls myCustomForm new myCustomForm.ID myCustomForm myCustomForm.Source Listing 8-14 Web Part code continued myCustomForm.Width new System.Web.UI.WebControls.Unit 475 myCustomForm.Height new Namespace SPCustomEntryWebPart Public Class CustomUserForm Protected Overloads Overrides Sub OnLoad e As EventArgs MyBase.OnLoad e Dim...
VB Mqk
lt ScriptableMember gt _ Public Sub SetRatingValue ByVal value As Integer If value gt 5 Then Each time that the slider control is updated, you will iterate over all of the registered Silverlight controls and call the SetRatingValue method, passing the new slider value. Add the method in Listing 7-31 to your class. The first thing you do is retrieve the list of registered Silverlight controls. Next, iterate over the controls skipping the current instance of this control. Next, get a reference...
Using HTML Cookies
Hidden fields are a great way to round-trip your data to and from the server. But in order to use that data across multiple browser sessions, you will need to use HTML cookies. Just like with the HiddenField, you create the cookie in the Web Part on the server. In the following code example, you will pass the background color down to the Silverlight control as a cookie. Listing 7-12 shows the code to add a cookie called BGColor to the Cookies collection. Unlike the HiddenField, you do not need...
Silverlight Streaming
Another approach would be to use Silverlight Streaming services. Although a detailed walk-through is out of the scope of this book, you could use the streaming services to host the XAP file. This is a great solution if you don't have access to the site to copy your XAP file to. In this scenario, you create an online account on the http silverlight.live.com site and upload your XAP file. Once that is done, you can access that XAP file from anywhere on the Internet. Listing 5-5 shows the code to...
Creating Editor Parts
You have now created the Silverlight Web Part Editor and need to add it to the collection of editors for your Web Part. To do this, override the CreateEditorParts. Add the code in Listing 6-12 to your SLWebPart.cs class. The first thing to do is create a list of EditorPart objects and add a new instance to your custom editor, SLEditorPart. Remember that to create a unique instance of the editor, pass the ID of the Web Part to the constructor. Next create a new EditorPartCollection and add your...
Display Mode
SharePoint has several different modes to use while displaying your Web Parts. There are three modes that are important when developing Web Parts Browse Mode This mode occurs when the user is using the site. This is the most used mode. Design Mode This mode occurs when the user clicks the Edit Page menu item under the Site Actions menu. The Design mode allows the user to add and remove Web Parts and to move the Web Parts around to different zones or reorder the Web Parts within the same zone....
Bringing It All Together
Throughout this book, we have discussed many different topics regarding SharePoint and Sil-verlight. For example, in Chapter 2, you saw how to create a simple Silverlight application and then integrate that application with a Web Part. You then learned many different ways to integrate Silverlight applications with SharePoint. For example, the different ways of integrating with Web Parts was discussed in Chapters 5 and 6 you saw how to build custom field types in Chapter 3 you walked through Web...
Adding a Feature to the Project
Let's start by adding a new feature to the BrandingSolution project that you have used throughout this chapter 1. Add a new SharePoint List Definition called SilverlightList. 2. Select ''Custom List'' from the List Definitions Settings Wizard dialog that will open. Leave all other options unselected and click OK to create the List Definition feature. Your Visual Studio solution should look similar to Figure 4-10. Solution Explorer - BrandlngSolutlon EI X ED- lJ CustomSltePage lil-...
VB Tid
Private Sub SPList_GetListItemsCompleted ByVal sender As Object, ByVal e As Dim listResults As XDocument Dim rows From item In _ RowsetSchema _ When you run your solution, you should see results similar to those shown in Figure 7-9. While in the end calling the built-in SharePoint Web Service was not very difficult in this example, it can get very complicated as the size of your application increases. Also, the Web Services do not support all of the functionality of SharePoint. To access all...
Creating a New Silverlight Project
Start by opening Visual Studio 2008 Professional with WssVSe. SharePoint development requires that you develop directly on the server. Windows Server 2008 has UAC security on by default. This means that in order to deploy your solution to the SharePoint site, you will need to run Visual Studio as an Administrator. 1. From the Start menu, right-click on the Microsoft Visual Studio 2008 program icon, choose ''Run as Administrator,'' and click Continue at the Confirmation prompt. 2. You want to...
Source Code
As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book's title either by using the Search box or by using one of the title lists , and click the Download Code link on the book's detail page to obtain all the source code for the book. Because many books have similar...
DataBind to the ListBox
At this point, you have created the SharePoint List, added the Service Reference, created a data-bindable ListBox, and called the GetListItems service. The last step is to handle the completed event to data-bind the results to the ListBox. Calling SharePoint Web Services can get a little complicated and is not as straightforward as calling the SharePoint API directly. For example, the GetListItems service call returns an ADO.NET data set formatted XML document like the one in Listing 7-25....
Listing Amended DISCO file
lt Page Language C Inherits System.Web.UI.Page gt lt Assembly Name Microsoft.SharePoint, Version 12.0.0.0,Culture neutral, PublicKeyToken 71e9bce111e9429c gt lt Import gt lt Import gt lt Response.ContentType text xml gt ref lt wsdl ,Response.Output gt docRef gt lt soap address binding q1 LikertServiceSoap gt lt soap address binding q2 LikertServiceSoap12 gt lt discovery gt 6. The same five lines of code that you add to the .disco file must be added to the .wsdl file. The other part of the file...
Adding a New Contact List to the SharePoint Site
This list will be the list you data-bind to in your Silverlight control. To add a new list in SharePoint 1. Select Site Actions gt Create from the page menu. 2. On the Create page, select Contacts under the Communications section, and name the list ContactsList. 3. Add some names to the list. Your list should look similar to Figure 7-8. You can now get the ContactsList in your Silverlight control using the built-in SharePoint Web Service, List.asmx. This Web Service allows you to read and write...
Custom List Page
In this section, you will learn how to customize a list by creating custom views for the list. A SharePoint list contains four pre-defined views for viewing and editing the data in the list AllItems.aspx, Disp-Form.aspx, EditForm.aspx, and NewForm.aspx. The default view is a file called AllItems.aspx. This is the normal grid view you see when you create a list. You can see these files using SharePoint Designer. Figure 4-8 shows the list forms using SharePoint Designer. In Figure 4-9 you can see...
Using Hidden Field
Silverlight is very good at interacting with the document object model of the browser that the control is hosted on. This opens up several different places to store data for use in your Silverlight application. One place is in a hidden HTML input field. In this simple example Listing 7-3 , the RatingId is set to a value of 4. ASP.NET and SharePoint manage postback communications using form fields. Silverlight can take advantage of this fact by using the browser bridge to read and write to the...
Create Navigation Menu
Once you create a custom site page, you need a way to reference it. Currently the user must know the URL to the custom site page in order to access it. One way to surface the custom site page is to add a link to it on the top Navigation menu. In this example, you will create a Feature Receiver for the CustomSitePage feature. Add a class to the CustomSitePage feature folder called FeatureReceiver, and add the code in Listing 4-14. This code is just standard SharePoint code to add and remove a...
Listing ASMX sample code
lt WebService Language C Class Service, LikertScaleWebService, Version 1.0.0.0, Culture neutral, PublicKeyToken a6ddf78b122c208b gt You can now deploy the Web Service, which can be done in a couple of ways. For example, you can deploy it to the _layouts folder, or you can deploy it to the _vit_bin folder, a virtual directory within the default SharePoint site. In the following example, you're going to deploy to the _layouts folder, but you'll do it in the next section of the chapter as a part...
Cleaning up Files and Web Parts upon Uninstall
You have seen how to use the power of Visual Studio and SharePoint solutions to deploy your Silverlight Web Part. There are a couple of issues that you need to understand in order to make developing with SharePoint a pleasant experience. The solution you developed in Chapter 5 contained two basic pieces the Web Part and the Silverlight control. Both of these get deployed to SharePoint using a feature, more specifically as a module and file element. The problem lies in the fact that by design...
Custom Web Parts
SharePoint uses a modular approach to building pages for a site. The unit of modularity in SharePoint is the Web Part. A Web Part is a container of functionality and user interface. Web Parts enable you to add and remove units of functionality and move them around the page without any programming. A SharePoint Web Part page consists of areas where Web Parts can be added, called Web Part Zones. SharePoint ships with several page templates with zones pre-defined. It also ships with several...
Different Ways to Integrate with SharePoint
There are several different ways in which you can integrate Silverlight applications with SharePoint. You might classify these in three different levels of integration with SharePoint 1 no touch, 2 low touch, and 3 high touch. The no-touch option is using the Silverlight Streaming media service, where you upload your Silverlight application to the service and it acts as the host for you. To do this, go to http silverlight.live.com , and sign in using your Live ID. After you log in, you'll have...
Using Customized Verbs
Web Parts contains a menu in the upper-right corner of the title bar. You can customize the menu and add new menu items called Verbs. The Verbs can be used to call server-side functions and client-side JavaScript functions. Figure 6-4 shows two custom Verbs, My Client Verb and My Server Verb, which have been added to the Web Part. You must override the WebPartVerbCollection to insert your custom menu items. Create a new WebPartVerb object. There are three overloads for creating a WebPartVerb,...
Using Custom Embedded JavaScript Files
The Silverlight control runs in the client's browser process. Silverlight can communicate with the browser through an HTML bridge built into the Silverlight control. The HTML bridge allows Silverlight to call JavaScript, and it allows JavaScript to call Silverlight. You'll see how this interaction works in more detail in Chapter 7. As part of your Silverlight application, you may need helper functions written in JavaScript. You could simply use the RenderContents method to write the JavaScript...
Listing Amended WSDL file continued
lt soap body use literal gt lt wsdl input gt lt wsdl output gt lt soap body use literal gt lt wsdl output gt lt wsdl operation gt lt wsdl binding gt lt wsdl binding name LikertServiceSoap12 lt soap12 binding gt lt wsdl operation name updateLikertList gt lt soap12 operation style document gt lt wsdl input gt lt soap12 body use literal gt lt wsdl input gt lt wsdl output gt lt soap12 body use literal gt lt wsdl output gt lt wsdl operation gt lt wsdl binding gt lt wsdl service name LikertService...
The Field Type Class
The first class that we'll discuss is the field type class. This class in our project called LikertScale.Field.cs is one that is automatically generated by Visual Studio and represents the core field type class. In this class, LikertScaleField inherits from SPFieldText, one of many possible derivations when creating field types. Also, there are two required constructors that live in this class as well. One of the core parts of this class is the FieldRenderingControl, which is a property that is...
Using Feature Receivers
The answer is to use a Feature Receiver. A Feature Receiver is how you can run custom code during the installation or uninstallation of a feature. You will see how to create a Feature Receiver that will clean up files deployed with the solution. Open the CustomWebParts project that you created in Chapter 5 or download the Chapter 6 code from the book. Remember to open Visual Studio as an Administrator. Add a new class to the SLWebPart project called FeatureReceiver. You can name this class...
Developing Your First Custom Field Type
Similar to the field types that ship with SharePoint, the custom field types have a control that will be rendered. This control will more than likely provide a way for you to store data, for example, custom text fields, dropdown lists, and so on. The goal of the custom field type should be to not only provide a way for the user to enter data into the control, but also to store that entered data in the custom list of which the custom field type is a part. For example, the scenario you'll walk...
JavaScript Only
There may be times when hard-coding the object tag in the source editor does not work for you. In this case, you could create the same results using only JavaScript. Listing 5-4 demonstrates dynamically creating the object tag inside a Div tag. Listing 5-4 Dynamically create object tag using JavaScript lt div id silverlightDIV gt lt script var slDIV slDIV.appendChild slDIV slDIV.innerHTML ' lt object width 300 height 200 gt lt param name source value XAP_Bin silverlightcontrol.xap gt lt object...
Editing Custom Web Part Properties
Web Parts can contain properties that are editable at run time. You can edit the Web Part while the page is in Edit mode or Run mode. Select the ''Modify Shared Web Part'' Verb from the Web Part menu while in Run mode, as shown in Figure 6-5, to open the Web Part Editor. The Web Part Editor opens on the right and enables you to modify the properties of the Web Part. You can see in Figure 6-6 that the properties are grouped into three categories Appearance This category is the only group...
Summary Eaz
You have seen in this chapter how you have a few options for how you integrate Silverlight into your SharePoint Web Parts. You can start with a relatively easy non-developer approach of using the Content Editor Web Part that is built into SharePoint. This chapter also showed you how to build your own custom Web Parts using Visual Studio and the Visual Studio Extensions for SharePoint. You have seen how you can build a robust, automated developer experience in Visual Studio giving you F5 build...
Using List Templates and Customer Lists
The SharePoint list templates are listed and described in the following table For storing and collaborating around documents. Supports features such as versioning, edit controls check-in and check-out , and workflow. Also supports integration with smart-client templates or documents. For social collaboration through wiki pages For storing objects like graphic and video files a special type of document library For storing contact information. Also supports integration with Outlook. For social...
Adding the Silverlight Video Player Application to the SharePoint Site
At this point, you've created the Silverlight application, and you've created and deployed the Web Part container for the Silverlight application. Thus, the last remaining step is to create a site that can host the Web Part. Before you can do this, it's important to have completed the steps to configure your server as outlined in Chapter 1. If you did not go through these steps, you should do that now to make sure that the Silverlight application renders properly. If you've completed the server...
Render Contents
Another way to inject Silverlight into your Web Part is to override the RenderContents method. The method is called by SharePoint when it is creating the contents inside of the Web Part. You can use the passed HTMLTextWriter variable to write raw HTML into the Web Part. In the example shown in Listing 5-10, you can see that you can add code before or after the HTML that is created using the CreateChildControls method. You could even use the write method to inject the code needed to display the...
W
WCF Windows Communication Foundation Services, WCF Windows Communication Foundation Services, Training list sample application configuring web methods, 259-263 overview of, 250 populating list collection of objects, 256-259 using getListIDInfo web method, 252-253 using getTrainingListData web method, 255-259 using updateList web method, 253-254 web methods, Web Services creating Web Service, 78-81 testing, 81 using getListIDInfo web method, 252-253 using getTrainingListData web method, 255-259...
Deploying the Web Service
If you're working along with us, you've now successfully created the Web Service that contains the core integration functionality that is, the bridge between the SharePoint custom field type and the Silverlight application. To deploy the Web Service will require 1. Ensuring that the service DLL in our case, LikertScaleWebService.dll is added to the global assembly cache GAC and 2. Deploying the service to a location that will allow applications to call the service. The first part of this step...
Deploying the Silverlight Application
At this point, both Web Parts are using the Silverlight application that you copied to the XAP_Bin folder. But this is not what you really want to do while developing. You want to have a single solution that builds and deploys not only the Web Part but the Silverlight application as well. Let's take a look at how to deploy our Silverlight application with the Web Part. In Visual Studio development, you can reference another project in the solution so that when you build the first project, the...
Creating a Custom List with the SharePoint Interface
One of the steps that consumers of your custom field type will need to take is to add a column to a list one that they create or one that you provision for them. Before jumping into the development of the custom field type, let's first walk through what the experience of adding a field type or column to a list looks like using the browser as the interface. To create a custom list using the SharePoint interface, do the following 1. Navigate to the home page of your SharePoint site, and then...
Configuring the Web Part Project for Deployment
With the code added, you are now ready to complete the second step configuring the Web Part project for deployment. To do this 1. From the main Visual Studio menu, click Project, and then select the project properties e.g., MySLAppWebPart Properties . This invokes the Properties view in your project. 2. Click the Debug tab. Check the Start Browser with the URL radio button, and then enter the root URL for your SharePoint site e.g., http localhost . 3. To test the deployment of the Web Part,...
Creating a Custom List Using Visual Studio
Now that you've seen how you can create a custom list through the browser interaction, let's take a look at how you can create a list programmatically using Visual Studio 2008. You can use Visual Studio to create a list programmatically 2. Select File gt New Project gt SharePoint, and you'll see several different choices available to you. 3. One of the options is ''List Definition,'' which you can use to build a custom list. If you provide a name for the list and click OK, you'll then be...
Debugging
Debugging your Silverlight Web Part requires a little manual setup in Visual Studio. There are two different pieces to debug the Web Part and the Silverlight application. This requires that you attach to two separate processes To debug your Web Part, you need to attach to the SharePoint process, which is called the 1. Open the CustomWebParts solution that you have been building in this chapter. 2. Open the SLWebPart.ce file and set a breakpoint. You also need to attach to the SharePoint worker...
Listing Web Part host container code
using System.Runtime.InteropServices using System.Web.UI.WebControls.WebParts using Microsoft.SharePoint.WebControls using Microsoft.SharePoint.WebPartPages protected override void OnLoad EventArgs e ScriptManager scriptManager scriptManager new ScriptManager this.Controls.Add scriptManager protected override void CreateChildControls myFirstSLApp new myFirstSLApp.ID mySLApp myFirstSLApp.Source myFirstSLApp.Width new System.Web.UI.WebControls.Unit 900 myFirstSLApp.Height new Imports...


















