Skip to main content

Karine Bosch

Go Search
Karine Bosch
  

The Silverlightness of SharePoint

  U2U Home
  U2U Course Calendar

 Other Belgian Bloggers

  Kris Vandermotten
  Peter Himschoot
  Serge Luca
  Bart De Smet
  Joris Poelmans
  David Boschmans
  Tom Mertens
  Stefaan Rillaert
  Yves Hanoulle
  Roy Dictus
The Silverlightness of SharePoint
The Silverlight BluePrint for SharePoint on Silverlight Beta 2 available now!

The Silverlight BluePrint for SharePoint on Silverlight Beta 2 is finally available for download here.

“The updated release of the Silverlight Blueprint for SharePoint is a little different from the original blueprints as with this release we've created a set of self-contained samples that using the blueprint methodology you can deploy to your SharePoint site to test out the Silverlight applications. The goal of the blueprints is to give you some guidance on how to integrate Silverlight applications with SharePoint. There are many possibilities here, and we've put together just a few to get you started.”

We have built in the latest new features of Silverlight, like Visual State Manager, HTTPWebRequest, data binding,

Hello World sample

This is a simple web part sample that shows how you can host a silverlight application from within a SharePoint web part.

In the Silverlight 2 beta 1 BluePrint for SharePoint we always deployed to a sub folder of the ClientBin that resides in the SharePoint web application but in this version of the Blueprint we also deployed to other locations. This sample contains a SharePoint web part that deploys to a document library and a web part that deploys to the LAYOUTS folder.

image

Slider custom field sample

This is a SharePoint custom field type containing a Silverlight slider. No major changes are made to this sample. As for the Silverlight 2 beta 1 BluePrint for SharePoint, the technique for using the InitParams property for the Silverlight control is explained here.

image

Media Viewer web part sample

This web part illustrates the use of a Picture Library containing pictures or movies. Information like the URL of the SharePoint site, the name of the Picture Library and the type of media is passed in the InitParams property of the Silverlight control. The data for the pictures is downloaded from within the Silverlight application using the HttpWebRequest object. This technique works completely asynchronous know. Changes to the Silverlight code itself include the use of the built-in ListBox control customized with styles and data binding.

The SharePoint web part is deployed to a document library.

image

Colleague Viewer web part sample

This sample illustrates the use of a WCF service for displaying colleague information out of the UserProfileManager. The WCF service runs in the SharePoint context. This WCF service is called from within the Silverlight application. Silverlight techniques used are styles and data binding.

The SharePoint web part is deployed to a SharePoint document library.

image

Navigation Control sample

This controls shows how you can develop a custom navigation control hosting a silverlight control. The data for the silverlight application is retrieved from within SharePoint and passed in an XML Data Island that can be accessed by the Silverlight application. Silverlight techniques used here are data binding and Visual State Manager to build the navigation scroll viewer. The silverlight application comes with a SharePoint master page feature.

image

Have fun with it! Hope you like it.

U2U SharePoint Job Definition Configurator

Some months ago I needed to develop a custom timer job for a customer. That time I learned a lot from this post of Andrew Connell.

When the timer job ran in test, we used an SPMinutesSchedule. But after some time, the job needed to be deployed in production. So I had to change the code in the FeatureReceiver event to have a weekly schedule. So I came to the idea of developing an application page in which you can configure and reschedule job definitions.

You can download the feature here. (A small remark: when deploying the solution using the delivered setup, be sure to only leave the Central Administration web application checked).

You can access the application page from a custom section in the Operations page of the SharePoint 3.0 Central Administration.

image

The page looks like the following:

page

In the first section you can choose the web application for which you want to configure a timer job. The dropdown list in the Job Definitions section is populated with the job definitions running on the selected web application.

The third section is an idea I got from Andrews article. In general jobs run for a complete web application. But this feature makes use of the SharePoint object property bag so that you can configure a custom timer job to run for one or more site collections of the selected web application.

sitecollections

If you schedule a job for a specific site collection, you have to add some extra code within your custom timer job, otherwise it will continue running for the whole application:

Execute 

Before you can use the U2U.SharePoint.Administration.JobConfigurationSettings class, you have to add a reference to the U2U.SharePoint.JobDefinitionConfigurator.dll, which is deployed in the 12\TEMPLATE\ADMIN\U2U.SharePoint.JobDefinitionConfigurator\bin folder:

AddReference

Remark: This means that the option of running a job for a specific site collection doesn't apply to standard SharePoint jobs!!

In the 4th section you can choose a schedule. If the selected job is already scheduled, the next occurrence date and the current schedule is displayed:

schedule

You can also enable/disable a timer job.

If you want to learn more about developing custom timer jobs:

- read the MSDN article: Creating Custom Timer Jobs in Windows SharePoint Services 3.0

- look at the Visual How-To: Creating, Deploying, and Debugging Custom Timer Jobs in Windows SharePoint Services 3.0

both from andrew connell. Andrew, thanks for sharing your knowledge!

This feature contains resources: all strings can be translated into your language. The resource files are deployed to the 12\Resources directory and are retrieved using the SPUtility.GetLocalizedString. Thanks to Renaud Comté for  helping me out with the resources.

You can read more about localization of strings here:

- Localisation des développements avec SharePoint

- Expression Builder et localisation

U2U Site Properties Feature: new version released...

This feature adds an hyperlink to the Settings page of your SharePoint site. When clicking it, a page with detailed information about the site properties is displayed.

[image]

You can read detailed information about this feature here.

You can download the feature here.

 Remark: The U2U Site Properties feature previously was part of the U2U SharePoint Solution Package. If you installed this solution, you will have to retract and delete this solution before you can install the new solution. The other features like U2U CAML Query Builder and U2U List Properties will be available soon in separate solutions.

U2U List Properties Feature: new version released...

This feature adds an hyperlink to the List Settings page of your list. When clicking it, a page with detailed information about the list properties is displayed.

[image]

You can read detailed information about this feature here.

This new version contains a bug fix for workflow properties.

You can download the feature here.

 Remark: The U2U List Properties feature previously was part of the U2U SharePoint Solution Package. If you installed this solution, you will have to retract and delete this solution before you can install the new solution. The other features like U2U CAML Query Builder and U2U Site Properties will be available soon in separate solutions.

U2U Caml Query Builder Feature: new version released...

This version contains following enhancements:

  • Code snippet generation
  • DateTime enhancements
  • Query options for SPQuery
  • Enhancements for Calendar lists

You can download the new version from here.

You can read the documentation here.

 Remark: The U2U Caml Query Builder previously was part of the U2U SharePoint Solution Package. If you installed this solution, you will have to retract and delete this solution before you can install the new solution. The other features like U2U List Properties and U2U Site Properties will be available soon in separate solutions.

Code Snippet Generation

With this feature you can build your CAML queries in a WYSIWYG way. When you click the Preview button, a Result section opens showing a text box with the query and a datagrid containing the rows resulting from the execution of the query.  Until now the text box only contained the CAML but there has always been some confusing about which tags to add where. So I thought it would be nice to generate code snippets that show you the proper use of the generated CAML. You can copy the code snippet, which is a complete function, and paste it right away in your code! You only have to pass the SPList object on which you want to execute the query.

You can now choose if you want to generate code in C# or VB.NET or get the CAML back as before. 

image

If you choose to have a code snippet in C# or VB.NET, you can choose if you want to get a DataTable returned or an SPListItemCollection. I'll show you the difference with the query I often use on the Employees table I have in my SharePoint site. The pure CAML looks like this:

image

If you ask to have a code snippet in C# returning an object of type DataTable, the code snippet looks like this:

image

If you ask to have a code snippet in VB.NET returning an object of type SPListItemCollection, the code snippet looks like this:

image

The preview page which is accessible from the item Edit Control block within the CAML Query dedicated list contains the same control.

One small note: if the Preview section doesn't open up when you clicked the Preview button, check if you filled out a name for the query at the top of the page.

Also this enhancement will be added to the windows version soon.

 

Date and Time enhancements

Until now I thought (and I'm sure I'm not the only one) that the time part of a date was always ignored by a CAML query when retrieving rows from a list using SPQuery or the GetListItems method of the Lists.asmx web service. I just recently read in a blog post that you CAN query time values so I decided to include it in the feature version of the U2U CAML Query Builder. A new version of the windows version will follow soon.

Let's say you have a table with date/time values and today we are the 5th June.

image

Open the CAML Builder via the Actions button on the list. Expand the filter on section and select the DateTime field. Choose an operator f.e. Greater than. Then you have 3 options:

  • Fixed date
  • Today
  • Now

image

If you choose Today, all dates greater than today's date will be retrieved:

image 

If you choose Now, then the query will take the time part into account and also todays rows with a time value in the future will be retrieved:

image

Take a look at the CAML query: an extra attribute is added to the DateTime field: the IncludeTimeValue attribute instructs SharePoint whether to take care of the time value or not:

<Where><Gt>

           <FieldRef Name='TestDate' />

           <Value IncludeTimeValue='TRUE' Type='DateTime'>2008-06-05T11:11:42Z</Value>

</Gt></Where>

You can also work with a fixed date. In this case you can also work with a time part or not: if you leave the 12 AM unchanged, the IncludeTimeValue attribute will not be added in the CAML and the query will not take a time value in account.

Fixed date

If you change this, the feature will add the IncludeTimeValue attribute and the query will take the time value into account when retrieving the rows.

image

 

Query options for SPQuery

Euh? you will say... yes, query options for SPQuery. Most of the query options you can pass to the GetListItems method of the Lists.asmx web service can be applied to properties of the SPQuery object. But a lot of developers don't know all the different possibilities and properties of this SharePoint object so I decided to shed a light on it and add a section called Query Options. When you have made your choices and click the Preview button, the code snippet in C# and VB.NET will reflect these choices. The pure CAML will not because the QueryOptions node is not part of the CAML that can be used with SPQuery.

This is the complete Query Options section:

image

You can limit the rows returned in the result set by setting the RowLimit property.

But lets start with an easy one: IncludeMandatoryColumns. Check this option in the Query Options section.

image

In the View Fields section I only indicate FirstName, LastName and Phone. As EmployeeID and EmailAddress are defined as required in the SharePoint List Settings, they are also returned in the result set:

image

There are also some options to query folder. If you don't check the Folder option, only the root folder is queried. If you want to query also the sub folders you have to set the Look in all folders and sub folders option:

image

When clicking the Preview button this causes the query.ViewAttributes property to be set to "Scope = 'Recursive'".

You can also query a sub folder. In that case you have to check the Specify a folder option. The text box will become available and will contain the url of the root folder as initial value:

image

When clicking the Preview button this causes the query.Folder property to the specified folder.

To conclude an example of the Query option ExpandUserField:

image

If your list is of type Agenda, you can set the Meeting Instance ID to return only rows of a certain meeting instance:

image

When you click the Save button, the query will be saved to a dedicated list for the CAML Query Builder. The query options will be saved as an xml node. If you want to see the code snippets again, navigate to the Caml Query List which is a list that stores.  This list does not show up on the Quick Launch but can be accessed via the View All Site Content button.

Caml Query List

... and choose Preview CAML Query from the Edit Control Block.

Preview

A page opens where you can view the code snippets. The query is executed and the resulting rows are        displayed in a datagrid.

 

Enhancements for Calendar lists

CAML queries for calendar lists are a bit more complicated, especially when working with recurring events. You can execute a normal CAML query on such a list and that's ok for normal events. But you will never get back the entries that are created based on a recurring event.

If your list is a Calendar, you will have to more options in the Query Options section:

image

If you check the Expand recurrences option also the instances created for a recurring event will be returned in the result set.

image

You can choose a fixed day from a date picker or you can choose Today. In that case the query will take the date on which the query is executed into account. You can also choose to see the recurring instances for a day, a week, a month or a year. The tool sets the CalendarDate property of the query and adds a DateRangesOverlap part to the Where clause.

The generated VB.NET code snippet then looks as follows:

image

In my example I have an event that occurs twice a week. These are the rows returned by the query when asking for a monthly overview as of the 1st June.

image

Note that each instance of a recurring event has the same ID as the recurring event that produced it. To learn more about the internals of a calendar list, read this excellent blog post.

 

Hope you like these extensions!

Determine if MOSS is installed by checking the Registry key

Today I found a post that explains a way to determine if MOSS is installed by checking on the existence of certain folders. Another way is to check on the existence of its the registry key.

image

The RegistryKey class is located in the Microsoft.Win32 namespace of the mscorlib.dll.

bool isMossInstalled = false;
string keyname = @"SOFTWARE\Microsoft\Office Server\12.0";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyname))
{
   if (key != null)
   {
       string version = key.GetValue("BuildVersion") as string;
       if (version != null)
       {
           Version buildVersion = new Version(version);
           if (buildVersion.Major == 12)
           {
              isMossInstalled = true;
           }
        }
   }
}

In a similar way you can determine if WSS is installed. In the registry you can find the following information:

image

Translated into code:

bool isWssInstalled = false;
string keyname = @"SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyname))
{
  if (key != null)
  {
    object wssvalue = key.GetValue("SharePoint");
    if (wssvalue != null && wssvalue.Equals("Installed"))
    {
      isWssInstalled = true;
    }
  }
}

U2U Caml Query Builder (Windows version): new version

This version includes the following updates:

- Query fields by ID

- GetListItemChanges (method of the Lists.asmx web service)

- GetListItemChangesSinceToken (method of the Lists.asmx web service)

- extra options of the QueryOptions part

- support for data type ModStat 

You can download the version 3.1.0.0 here.

Remark for those who have put the dlls in the GAC: the version of U2U.SharePoint.CAML.dll has NOT been augmented so the users of the feature version are not bothered. The versions of U2U.SharePoint.CAML.Client.dll and U2U.SharePoint.CAML.Server.dll have also been raised to version 3.1.0.0 because of the changes. So users who use these dlls for custom development will have to check. But as I didn't remove any method, no interfaces should be broken.

Query fields by ID

In most of the cases list items are retrieved using the <FieldRef Name="x" /> syntax. But there are cases that you need to query by ID. In that case you can set the Query by ID option in the upper right corner of the form.

camlv2querybyid

Your query will look like the following:

camlv2querybyid2

Keep in mind that when you already built a query the default way and then choose to build the query by ID, your query will be cleared and you will have to start over again.

The ModStat data type

In case a column in your list is of data type ModStat, a combo box with the values Approved, Pending and Rejected will be displayed. A query containing such a field will look as follows:

<Where>
      <Eq>
         <FieldRef Name="_ModerationStatus" />
         <Value Type="ModStat">Approved</Value>
      </Eq>
</Where>

GetListItemChanges

With this method you can retrieve items that have been modified since a certain date. If you pass no date, all list items will be returned.

For a more in-depth explanation of this method I refer to:

- http://msdn2.microsoft.com/en-us/library/lists.lists.getlistitemchanges.aspx

To build a CAML query for the GetListItemChanges, open your site using the web service mode:

camlv2connectws

Right-click the list for which you want to build a query from the treeview at the left and choose GetListItemChanges:

camlv2getlistitemchanges1

You get 3 tabs to build your query:

- the ViewFields tab as in the GetListItems method

- the Contains tab where you can define a sort of filter

- the Since tab to specify a date

image

If you want to specify a date from which changed rows must be returned, check the Retrieve changes as of check box and choose a date from the date picker. In case you also need to specify a time, use the up/down controls. The date will be passed to the GetListItemChanges method.

GetListItemChangesSinceToken

With this method you can retrieve  list items that have been changed. On the first run of the method, the server returns all rows and a token. In the next runs you pass this token back to the server and only the modified rows since that token will be returned.

For a more in-depth explanation of this method I refer to:

- http://blogs.msdn.com/sharepointdeveloperdocs/archive/2008/01/21/synchronizing-with-windows-sharepoint-services-part-1.aspx

- http://msdn2.microsoft.com/en-us/library/lists.lists.getlistitemchangessincetoken.aspx

To build a CAML query for the GetListItemChangesSinceToken, open your site using the web service mode. Right-click the list for which you want to build a query from the treeview at the left and choose GetListItemChangesSinceToken.

You get 5 tabs to build your query:

- the ViewFields tab as in the GetListItems method

- the Query tab as in the GetListItems method where you can define a more complex filter and a sort order

- the Contains tab where you can define a sort of filter

- the ChangeToken tab to specify a token returned by the server

The Query tab and the Contains tab are mutually exclusive. This means that you can build a (more complex) filter with a WHERE clause or a simple CONTAINS filter.

image

The set of query options is a bit more extended for this method.

image

Don't forget, if you want to use the methods GetListItemChanges and GetListItemChangesSinceToken you can use the CAML generated by this tool but you can also use the underlying dlls U2U.SharePoint.CAML.dll and the U2U.SharePoint.CAML.Client.dll. If this is your case, don't hesitate to ask for a code sample!

How to modify the custom People/Groups type column of a SharePoint List using Lists.asmx

Based on this post I wanted to integrate Sowmyan's findings into the U2U CAML Query Builder. But I came to the conclusion that I can also update a user column in a list using the UpdateListItems method of the Lists.asmx web service with following query:

<Batch PreCalc='TRUE' OnError='Continue'>
   <Method ID='1' Cmd='Update'>
      <Field Name='ID'>12</Field>
      <Field Name='AssignedTo'>9</Field>
   </Method>
</Batch>

I don't specify a field type and for the user column I only specify the ID of the user I want to assign the task to.

To retrieve rows using the GetListItems method I couldn't use the ID of the user but I can use his/her name:

   <Where>
      <Eq>
         <FieldRef Name='AssignedTo' />
         <Value Type='User'>Karine Bosch</Value>
      </Eq>
   </Where>

Luckily it doesn't always need to be complicated image

Retrieving Items from a SharePoint List with Powershell and the SharePoint Lists.asmx

There is not yet much information on the net on how to combine Powershell with the SharePoint web services. One of the most used methods of the Lists.asmx, which is a standard SharePoint web service, is the GetListItems method. With this method you can retrieve all list items but also a subset of data when you use a CAML query. You can also limit the number of columns returned if you use a ViewFields node.

If you read previous posts and saved the necessary environment variable declarations in your profile, the only thing you should do to start is:

$listservice = New-Object Lists

$listservice.Credentials=[System.Net.CredentialCache]::DefaultCredentials

Otherwise you have to go back to my post and execute the first steps to declare the environment variables and compile and load the lists dll.

In its most simple form, you can retrieve all list items of a certain list:

$result = $listservice.GetListItems("Customers", $null, $null, $null, $null, $null, $null)

$result is an xml node containing the following:

image

It's the data element that contains the list items.

If you execute something like the following, you will get the last name of each customer in the result set:

$result.data.row | foreach ($_.ows_Title)

image

When working with the Lists.asmx SharePoint web service, all fields are prefixed with ows_.

If you want to retrieve a subset of list items you have to pass a CAML query to the GetListItems method. For example, if you want to retrieve all customers living in the city Bendigo, you have to create following CAML query:

<Query><Where><Eq><FieldRef Name='WorkCity' />

<Value Type='Text'>Bendigo</Value></Eq></Where></Query>

You execute the GetListItems method as follows:

$query = "<Query><Where><Eq><FieldRef Name='WorkCity' /><Value Type='Text'>Bendigo</Value></Eq></Where></Query>"

$result = $listservice.getlistitems("Customers", $null, $query, $null, $null, $null, $null)

image

You can always build your more complex queries with the U2U Caml Query Builder which exists in windows version (download) and feature version (download). Consult my blog or the U2U web site for more detailed information about building CAML queries with the tools. 

Another way to limit the number of rows returned is specifying a row limit, with or without a query:

$result = $listservice.getlistitems("Customers", $null, $query, $null, 3, $null, $null)

If you want to view the complete content of each row, you can execute the following:

image

You can also limit the number of columns returned in the result set by specifying a ViewFields node. Lets only retrieve the Title and Email for customers living in Bendigo:

[xml]$viewfields = "<ViewFields><FieldRef  Name='Title' /><FieldRef Name='EMail' /></ViewFields>

$result = $listservice.getlistitems("Customers", $null, $query, $viewfields, $null, $null, $null)

As you view the result you will notice that indeed the Title and the Email field are returned but also another bunch of fields. These are the system fields and will always be returned, even if you use the IncludeMandatoryColumns element of the QueryOptions (because this only works for custom fields defined as required). For completeness, you define QueryOptions as follows:

[xml]$queryoptions = "<QueryOptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns></QueryOptions>"

$result = $listservice.getlistitems("Customers", $null, $query, $viewfields, $null, $queryoptions, $null)

You can read more about the GetListItems method on the msdn site.

If you need extra information about this method or about other method on other SharePoint web services, you can leave me a comment.

Nick, now you owe me a beer!

U2U Caml Query Builder Feature: new version

A new version of the U2U CAML Query Builder is released today!

This version includes the following updates:

- extra data types like ModStat: when selecting a column of type ModStat, a dropdown with possible values will be displayed

- it is now possibility to add more than 2 fields in the WHERE clause

- you can now build a query where the fields are filtered and sorted by ID instead of by name. This is because some type of queries require filtering by ID.

You can download the full U2U SharePoint Solution package here.

It contains features like List Properties, Site Properties and Move/Copy list items. (Only activate the feature you need).

How to add more filters to the where clause?

In the Filter On section fill out a first filter. If you want to add a second one, click the Add a column to the where clause hyperlink:

image

This adds a second filter to the Filter On section. You can add as many filters you need and indicate whether you want to Or or to And.

image

Click on the Preview button to see the actual query and the resulting data after running the query against the list:

 image

You can save your query and it will be saved to a specific CAML Query List from where you can use and preview your queries.

How to build a query to filter and sort fields by ID?

In the previous example the query was filtered by field name:

<FieldRef Name='LastName' />

But you can also execute a query with a filter and a sort by ID. To achieve this, there is a new section added under the query Name section:

image

The default is query by name but you can choose the option Query by field ID. The user interface stays the same but the previous query looks like this while the resulting data is still the same (don't forget to press the Preview button again):

<Query>
   <ViewFields>
      <FieldRef Name='EmployeeID' />
      <FieldRef Name='LastName' />
      <FieldRef Name='JobTitle' />
      <FieldRef Name='Phone' />
      <FieldRef Name='EmailAddress' />
   </ViewFields>
   <Where>
      <Or>
         <Or>
            <BeginsWith>
               <FieldRef ID='66cb931d-ff9c-47b2-8e13-d3554c1798af' />
               <Value Type='Text'>E</Value>
            </BeginsWith>
            <BeginsWith>
               <FieldRef ID='66cb931d-ff9c-47b2-8e13-d3554c1798af' />
               <Value Type='Text'>F</Value>
            </BeginsWith>
         </Or>
         <BeginsWith>
            <FieldRef ID='66cb931d-ff9c-47b2-8e13-d3554c1798af' />
            <Value Type='Text'>G</Value>
         </BeginsWith>
      </Or>
   </Where>
   <OrderBy>
      <FieldRef ID='13d408ed-79a3-4b67-a384-e4bac030df9d' Ascending='False' />
   </OrderBy>
</Query>

As you can see in this query all FieldRef elements in the Order By and the Where clause have an ID attribute, except the FieldRef elements in the ViewFields part. The weird thing is that when I replace the Name attribute with an ID attribute, only the ID field (and some other required fields) is returned. It seems ViewFields cannot handle the <FieldRef ID='[guid]' /> construct.

If you use this query against an SPQuery object, you have to:

- remove the <Query></Query> tags (I know this already caused a lot of confusion among the developers community but I need a root in an XML document)

- Assign the ViewFields node to the ViewFields property of the SPQuery object.

- Assign the Where and Order By node to the Query property of the SPQuery object.

This functionality and some other will be soon released in the windows version of the U2U CAML Query Builder.

Hope you like the new functionality!

1 - 10 Next
Silverlight BluePrint for SharePoint

 Download my Features

  U2U CAML Query Builder (feature version) version 3.1.0.0
  Site Properties feature version 1.0.0.0
  Site Properties feature version 1.0.0.0
  U2U CAML Query Builder version 3.1.0.0 (windows version)
  U2U Job Definition Configurator feature version 1.0.0.0

 Recommended Books

Thumbnail
Thumbnail
Thumbnail
Thumbnail
Thumbnail
Thumbnail
Thumbnail

 ‭(Hidden)‬ Admin Links