19 September 2007

Event Receiver Values

For those of you that need a quick conversion of the event receiver types, here they are:

  • SPEventReceiverType.ItemAdding = 1
  • SPEventReceiverType.ItemUpdating = 2
  • SPEventReceiverType.ItemDeleting = 3
  • SPEventReceiverType.ItemCheckingIn = 4
  • SPEventReceiverType.ItemCheckingOut = 5
  • SPEventReceiverType.ItemUncheckingOut = 6
  • SPEventReceiverType.ItemAttachmentAdding = 7
  • SPEventReceiverType.ItemAttachmentDeleting = 8
  • SPEventReceiverType.ItemFileMoving = 9
  • SPEventReceiverType.FieldAdding = 101
  • SPEventReceiverType.FieldUpdating = 102
  • SPEventReceiverType.FieldDeleting = 103
  • SPEventReceiverType.SiteDeleting = 201
  • SPEventReceiverType.WebDeleting = 202
  • SPEventReceiverType.WebMoving = 203
  • SPEventReceiverType.ItemAdded = 10001
  • SPEventReceiverType.ItemUpdated = 10002
  • SPEventReceiverType.ItemDeleted = 10003
  • SPEventReceiverType.ItemCheckedIn = 10004
  • SPEventReceiverType.ItemCheckedOut = 10005
  • SPEventReceiverType.ItemUncheckedOut = 10006
  • SPEventReceiverType.ItemAttachmentAdded = 10007
  • SPEventReceiverType.ItemAttachmentDeleted = 10008
  • SPEventReceiverType.ItemFileMoved = 10009
  • SPEventReceiverType.ItemFileConverted = 10010
  • SPEventReceiverType.FieldAdded = 10101
  • SPEventReceiverType.FieldUpdated = 10102
  • SPEventReceiverType.FieldDeleted = 10103
  • SPEventReceiverType.SiteDeleted = 10201
  • SPEventReceiverType.WebDeleted = 10202
  • SPEventReceiverType.WebMoved = 10203
  • SPEventReceiverType.EmailReceived = 20000
  • SPEventReceiverType.ContextEvent = 32766
  • SPEventReceiverType.InvalidReceiver = -1
This was something I had to do in order to build my ElementManifest.xml file for a feature that I was recently developing. In the SDK it mentions that I need to use the integer value of the SPEventReceiverType enumeration. When you click on the provided hyperlink, you see a list of the enumerations without an integer value -- hopefully this will help those needing this list.

10 September 2007

My First Custom Site Definition

Another recent project has lead me down the path of creating custom site definitions for use within my organization. My requirements are as follows:

  1. Must be based off the current team site definition
  2. Must include a PowerPoint slide library with example slides (required MOSS standard)
  3. Must include a picture library with example photographs
  4. Must remove SharePoint branded logo and use company logo instead
  5. Should include custom announcements on the front page
  6. Should provide links to common staff resources

So, the first thing I did was to download the VS 2005 Extensions for SharePoint Services 3.0. Once installed on my development server, I created a new project based off the Team Site Definition included as part of the newly installed VS 2005 Extensions for SharePoint Services 3.0.

TSD

When the project is created, the project automatically opens up the onet.xml file that needs to be modified to create the additional lists. I need to include two new lists that are not part of the original definition for a team site. This includes a picture library and a slide library. Find the Lists element in the onet.xml file and add two new entries:

<List Title="Shared Pictures"
         QuickLaunchUrl="Pictures/Forms/AllItems.aspx"
         Url="Pictures"
         Type="109"
         FeatureId="00bfea71-52d4-45b3-b544-b1c71b620109"/>
<List Title="Shared Slides"
         QuickLaunchUrl="Slides/Forms/AllItems.aspx"
         Url="Slides"
         Type="2100"
         FeatureId="0BE49FE9-9BC9-409d-ABF9-702753BD878D"/>

The first list item is based on type 109 which is the default picture library that is included as part of SharePoint. I have to include the feature that the list is based on as the FeatureId attribute. Notice that I have given a custom url instead of a url that includes a space. This should help my users with navigation to these libraries.

The second list took a little investigation. I opened up an explorer window and viewed the contents of <Program Files>/Common Files/Microsoft Shared/web server extensions/12/FEATURES folder and looked for the Slide Library feature. I opened the folder and then viewed the contents of the feature.xml file. I copied the GUID that was in the file and placed this as my GUID on the new list. I also noticed that the list type (from opening the referenced files in the elementmanifests node) was 2100. Now I have all I need to create a new Slide Library.

The next step was to add the necessary features to the WebFeatures node of the onet.xml file. Since both features need to be activated at the site level (and not the collection), I ignore the SiteFeatures node and made sure that my WebFeatures node included the following:

<WebFeatures>
     <Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5"/>
     <!-- TeamCollab Feature -->
     <Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4"/>
     <!-- MobilityRedirect -->
     <Feature ID="00bfea71-52d4-45b3-b544-b1c71b620109"/>
     <!-- Picture Library -->
     <Feature ID="0BE49FE9-9BC9-409d-ABF9-702753BD878D"/>
     <!-- Slide Library -->
</WebFeatures>

Now I have everything set up and can provision a site that will automatically include both a slide library and a picture library by default.

Next, I need to include some sample photos and slides for both of these new libraries. This is done using modules. You will notice there are two places in the onet.xml file that include a Modules node. The first one is included in the Configuration node and the second is in a Modules node outside of the Configuration Node. We need to include references to the new modules inside the Configuration node first.

So, simply add a new Module node for each of the new libraries. You can use the model already in-place for the Default module (this module includes the default.aspx page for the site and it's included web parts). I called my modules Images and Slides.

<Modules>
        <Module Name="Default"/>
        <Module Name="Images"/>
        <Module Name="Slides"/>
</Modules>

Now I move to the Modules node and define the contents of the Images and Slides modules.

    <Module Name="Images" Url="Pictures" Path="" List="109">
      <File Url="coastaltown.jpg" Type="GhostableInLibrary">
        <Property Name="Title" Value="Coastal Town"/>
        <Property Name="ImageCreateDate" Value="<ows:TodayISO/>"/>
        <Property Name="Description" Value="A nice quiet view of a coastal village as one might view on the Mediterranean sea."/>
      </File>
      <File Url="steamshed.jpg" Type="GhostableInLibrary">
        <Property Name="Title" Value="Old Steam Shed"/>
        <Property Name="ImageCreateDate" Value="<ows:TodayISO/>"/>
        <Property Name="Description" Value="An old logging shed powered by a steam furnace"/>
      </File>
    </Module>
    <Module Name="Slides" Url="Slides" Path="" List="2100">
      <File Url="SharePoint_Overview_Training_011.ppt" Type="GhostableInLibrary">
        <Property Name="Presentation" Value="SharePoint Overview Training" />
        <Property Name="Description" Value="What is the SharePoint?" />
      </File>
      <File Url="SharePoint_Overview_Training_174.ppt" Type="GhostableInLibrary">
        <Property Name="Presentation" Value="SharePoint Overview Training" />
        <Property Name="Description" Value="SharePoint Team Site Layout" />
      </File>
      <File Url="SharePoint_Overview_Training_175.ppt" Type="GhostableInLibrary">
        <Property Name="Presentation" Value="SharePoint Overview Training" />
        <Property Name="Description" Value="Global Links Bar" />
      </File>
    </Module>

You must set the file type attribute to GhostableInLibrary or the items will not be displayed in your libraries. Also, each Module node gives the files their destination location. This is done view that url attribute and the list attribute. I then set some properties on each of the items that I am including in these libraries using the Property nodes.

Now, to remove the SharePoint logo and add your own, I just need to make changes to the Default module. See the changes below:

    <Module Name="Default" Url="" Path="">
      <File Url="default.aspx" NavBarHome="True">
        <View List="$Resources:core,lists_Folder;/$Resources:core,announce_Folder;" BaseViewID="0" WebPartZoneID="Left"/>
        <View List="$Resources:core,lists_Folder;/$Resources:core,calendar_Folder;" BaseViewID="0" RecurrenceRowset="TRUE" WebPartZoneID="Left" WebPartOrder="2"/>
        <AllUsersWebPart WebPartZoneID="Right" WebPartOrder="1">
          <![CDATA[
                   <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:iwp="http://schemas.microsoft.com/WebPart/v2/Image">
                        <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
                        <TypeName>Microsoft.SharePoint.WebPartPages.ImageWebPart</TypeName>
                        <FrameType>None</FrameType>
                        <Title>$Resources:wp_SiteImage;</Title>
                        <iwp:ImageLink>/PublishingImages/norm_logo.png</iwp:ImageLink>
                        <iwp:AlternativeText>Company Logo</iwp:AlternativeText>
                   </WebPart>
                   ]]>
        </AllUsersWebPart>
        <View List="$Resources:core,lists_Folder;/$Resources:core,links_Folder;" BaseViewID="0" WebPartZoneID="Right" WebPartOrder="2"/>
        <NavBarPage Name="$Resources:core,nav_Home;" ID="1002" Position="Start"/>
        <NavBarPage Name="$Resources:core,nav_Home;" ID="0" Position="Start"/>
      </File>
    </Module>

Now I have created the site definition, all I need to do is copy the files referenced in my modules to the Site Definition folder of my project. This will be compiled into the WSP solution file by the project. Keep in mind that these files will increase the overall size of your WSP solution file.

Now, I deploy the solution by right clicking on the project and choosing Deploy.

TSDDEPLOY

This will build my project files and automatically deploy it to the local sharepoint server. When I navigate to my site and choose to create a new site, my custom site definition is included under a newly created category, Development. When I provision the new site, it includes my new libraries and example files.

If you want to make changes to the category, just right click on the project and choose properties. Then you can click on the SharePoint Solution tab and make modifications to the solution and site definition files from here.

06 September 2007

Using Web Services in SharePoint Designer

I recently had a project in which I needed to create a course roster management system for our faculty to view a list of students in their class. We had already created a web service for the management of these courses for an older system, but since we have been moving towards SharePoint, when it was time to redesign this application we found SharePoint to be a strong candidate.

First, I created a new blank team site in SharePoint as my scratch pad. I connected to the site using SharePoint Designer and created two new ASPX pages. One would by my faculty course roster that included all of the courses the member was teachinng for the semester (facultycourses.aspx). The second one would have a list of students for a single course (courseroster.aspx).

Next, I opened up my data sources and added a new XML Web Service data source. I pointed the web service to my roster management course list by typing the URL in the top box. Since I'm only reading data for display, I will only need to configure the Select data command. I then selected the operation that returns a list of courses for a specified faculty member. I have one parameter that the webservice expects, Login. I specified a default value (for testing) and then checked the checkbox for The value of this parameter can be set via a Web Part connection. This allows me to use parameters in a data view to dynamically query the web service. Since this web service is used to both return courses and student rosters, I created a copy of the web service and pointed to the method that returns a list of students based on a specified course.

datasourceprops

soapenvelopNext, from the Data Source that returns a list of courses, I right clicked and selected Show Data. This performed a query to the web service and returned the schema of the data. I select the fields I want to display and then click on Insert Selected Fields as > Multiple Item View. This inserts a data view with the selected items. I now have the data ready for some modifications. The first thing I need to do is add a link to the student roster page, so I selected the column for the name of my course. From the Insert Menu, I chose HTML > Hyperlink. When I am prompted for properties, I provided the url StudentRoster.aspx?SYN={SYN}.

Next, I selected the dataview and then clicked on Data View > Parameters. In the dialog I have a parameter named Login. I clicked on the parameter and set the source to a query string. (My eventual goal for the finished application is to have SharePoint pass this information to the data view parameter. I'll let you know when I figure out how to accomplish this). Now I'm ready to move on to the StudentRoster page to get it setup.

facultypagerough

For the student roster, I follow the same instructions but set my data source to the data source that returns students in a course. I need to set the parameters for the data view to use a query string value that I set in the course link. This is the value SYN. After I save the page, I can now click on any course from the faculty courses page and display the students for that course.

Finally, to get these pages integrated into SharePoint, on each page I choose Format > Mater Page > Attach Master and use all of the defaults. This will wrap the sharepoint master page around the ASPX file and thus integrate this mini-application into sharepoint.

attachmaster

Here's my faculty page final result:

facultypagedone