donderdag 4 maart 2010

SharePoint 2010: What's new for developers (high level)

In this post I will give a high level view of what you as a developer can expect in SharePoint 2010.

First of all, as I also mentioned in one of my previous posts, SharePoint 2010 can be installed on Windows 7 and Windows Vista, both client OS's. This might be a significant enhancement for many development teams. It is also possible to install SharePoint 2007 on Windows Vista but this is not supported by Microsoft. But now with the new version of course it is.

As we all know, SharePoint Server 2010 is the next version of the SharePoint technology stack. There will be three different SKUs for SharePoint Server 2010:
•SharePoint 2010 Server Enterprise
•SharePoint 2010 Server Standard
•Microsoft SharePoint Foundation

SharePoint 2010 Server only runs on 64-bit operating systems. This is different from MOSS 2007 and WSS 3.0 which ran on either a 32-bit OS and a 64-bit OS. SharePoint 2010 Server is the first version of the product that supports installation on a client OS for development. The supported clients Os's included 64-bit version of Windows 7 and Windows Vista.

In SharePoint 2010, a lot of new services are introduced. For example, 'Word Services' which you can use to convert documents to PDF and print them.


 This is how the new Team Site looks in SharePoint 2010. As you can see the master page has changed quiet a bit. The 'site actions' menu is now placed on the left. This was very confusing for me at first :) . The home page is a wiki page, placed in the 'SitePages' folder and there are new lists and galleries created behind the scenes.



There's been a big change in the SharePoint menu's as these are now also using the well know ribbon interface. You can think of the ribbon interface a contextual menu that will change depending on what the situation is. Clicking on one of the buttons will fire up a popup window. So no more postbacks for every click you make. A lot of these functionalities are based on AJAX technology to give the user a more Web 2.0 experience.
These ribbons are customizable and Microsoft will also give you access to the many javascript functions which are used in these menus.


We have probably all used one or more of these objects to access certain parts of our SharePoint sites. These objects are backwards compatible in the 2010 version.


The SharePoint developer dashboard is, in my opinion, one of the most things you will use as a developer. It can be accessed from within the GUI and will show you information like:

•How long did the request take to run?
•What event handlers were fired?
•In what sequence did these event handlers fire?

Remember that, at this point, there is now way you can turn the developer dashboard on or off via the GUI. But you can do it via the command line or via code:



As a developer you will most of the time be busy debugging your code. Make sure you are running Visual Studio 2010 as an administrator or you might not be able to debug at all. This is mainly due to the fact that the identity behind the Windows process for Visual Studio 2010 needs sufficient rights to be attached to and debug the IIS Worker Process (W3WP.EXE).

The Visual Studio development team has done a huge effort in making new tools for SharePoint developers. In one of the next posts I will go into much further detail about these. For now, just note that you can now have a compleet structural overview of your SharePoint site right with Visual Studio showing you all your lists, features, content types, ... . You also have access to alot of new project templates like 'Visual Web Part' (which I showed you in some of the previous posts), 'Import WSP' (which allows you to import WSP packages created by other tools/people), ... . Also the solution structure has changed completely. It will contain stuff like a 'Package' and 'Artifacts'. We will go more into detail in one of the next posts.

Microsoft also put a huge investment in SharePoint Designer 2010. Tought of as sometimes useless by many SharePoint 2007 developers, SPD 2010 has become a more mature tool. It offers a lot of functionalities which really offer a great added value. For example you can now export your SPD 2010 creations as a WSP and, for example, import them in Visual Studio 2010 to further customize them or extract the parts you need and add them to a project or you can just send your WSP file to another person which will use its contents in his project.
The workflow designer is much more powerfull and can now also create reusable workflows which can be hooked to multiple lists, something which was, strangely enough, not possible with SPD 2007.

Microsoft is really going the Powershell way with SharePoint as well. There are a lot of cmdlets you can use and of course you can also write your own super scripts against the object model. You can already find scripts on the net which will completely automate the SharePoint 2010 installation process. I suggest you start learning Powershell because in the end it will replace stsadm.

This was a first, very high, overview of some of the things to expect in SharePoint 2010 (mainly as a developer). In the next posts, I will dive into much more detail about the different topics addressed here.

woensdag 10 februari 2010

Customizing SharePoint list toolbars

Many clients ask for custom toolbars where for example, the new button is hidden so users can only upload files. In this post I will explain you how to do this if you're able to start from a point where you can still use list definitions.
If , for any reason, you need to do this with already existing libraries, this post will be no good for you but don't worry, because in some of the next posts, I will explain a cool method to do this as well.

1. Create a list definition to start from
First we need some kind of list definition to start from. Most of the time I use the SharePoint Solution Generator to generate a solution with the list definition files in it. So just create your list in the GUI and create a list definition with this tool.

2. Discovering the templates
All templates for rendering the toolbars found in any list in SharePoint, can be found in the defaulttemplates.aspx file which is located in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES folder.
To check which template your list definition is using, search for the property "ToolbarTemplate".

3. Creating your own control template
  1. Copy the defaulttemplates.ascx and place it in the same location C:\Program Files\Common Files\Microsoft Shared\webserverextensions\12\TEMPLATE\CONTROLTEMPLATES. You can give any custom name to the ascx file.
  2. Remove all the rendering templates from the custom defaulttemplates.ascx except the “DocumentLibraryViewToolbar”. Change the ID to a custom name like “MyCustomViewToolbar”.
  3. Remove the "SharePoint: UploadMenu" control rendering from the template and save the custom defaulttemplates.ascx. Of course you can delete other control renderings if you want to hide other buttons as well.
  4. Open the schema.xml file of your list definition you just created and in the default view (BaseViewId=1) add the “ToolbarTemplate” attribute which mentions your custom rendering template created without the upload menu. This XML snippet could look something like this:

    <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" ToolbarTemplate="MyCustomViewToolbar" DisplayName="$Resources:core,All_Documents;" DefaultView="TRUE" MobileView="True" MobileDefaultView="True" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/dlicon.png" Url="Forms/AllItems.aspx"><!-- _locID@DisplayName="camlidDc1" _locComment=" " -->
  5. Save your changes, install and activate the feature for your custom list defintion and you're good to go. If all goes well you will see your template end up in the collection of possible list templates when you want to create a new list.

dinsdag 9 februari 2010

dinsdag 12 januari 2010

Custom people field in SharePoint 2007

Some time ago I needed to create a people field which had to have a default value. The default value had to be the current user. This is not possible out of the box so I needed to create a custom field type for this. Because there was very little information on creating a custom people field on the net, I will explain the method in this post.

1. Create the custom field xml
This file needs to go in 12/TEMPLATE/XML. Make sure it starts with 'fldtypes_'. I will call it 'fldtypes_customPeopleField'.

Here is the xml. It will describe some properties of this field like the type name, displayname and the class which will take care of the actual logics.

   1: <?xml version="1.0" encoding="utf-8"?>



   2: <FieldTypes>



   3: <FieldType>



   4: <Field Name="TypeName">CurrentUserAsDefault</Field>



   5: <Field Name="ParentType">User</Field>



   6: <Field Name="TypeDisplayName">Current User</Field>



   7: <Field Name="TypeShortDescription">People field with current user as default value</Field>



   8: <Field Name="UserCreatable">TRUE</Field>



   9: <Field Name="ShowInListCreate">TRUE</Field>



  10: <Field Name="ShowInSurveyCreate">TRUE</Field>



  11: <Field Name="ShowInDocumentLibrary">TRUE</Field>



  12: <Field Name="ShowInColumnTemplateCreate">TRUE</Field>



  13: <Field Name="FieldTypeClass">MyProject.ContentTypes.CurrentUserField, MyProject.ContentTypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f443cebe7d24f267</Field>



  14: <Field Name="FieldEditorUserControl">/_controltemplates/UserFieldEditor.ascx</Field>



  15: <Field Name="Sortable">TRUE</Field>



  16: <Field Name="Filterable">TRUE</Field>



  17: <RenderPattern Name="DisplayPattern">



  18: <FieldSwitch>



  19: <Expr>



  20: <Property Select="FieldRef"/>



  21: </Expr>



  22: <Case Value="">



  23: <Switch>



  24: <Expr>



  25: <Column/>



  26: </Expr>



  27: <Case Value="">



  28: <FieldSwitch>



  29: <Expr>



  30: <Property Select="SuppressNameDisplay"/>



  31: </Expr>



  32: <Case Value="TRUE">



  33: <HTML><![CDATA[<table cellpadding=0 cellspacing=0 dir="]]></HTML>



  34: <Property Select="Direction" HTMLEncode="TRUE"/>



  35: <HTML><![CDATA["><tr><td style="padding-right: 3px;">]]></HTML>



  36: <HTML><![CDATA[ <img border="0" valign="middle" height="12" width="12" src="/_layouts/images/blank.gif" > </td></tr></table>]]></HTML>



  37: </Case>



  38: </FieldSwitch>



  39: </Case>



  40: <Default>



  41: <FieldSwitch>



  42: <Expr>



  43: <Property Select="LookupType"/>



  44: </Expr>



  45: <Case Value="Computed">



  46: <LookupColumn/>



  47: </Case>



  48: <Default>



  49: <LookupColumn HTMLEncode="TRUE"/>



  50: </Default>



  51: </FieldSwitch>



  52: </Default>



  53: </Switch>



  54: </Case>



  55: <Default>



  56: <LookupColumn HTMLEncode="TRUE"/>



  57: </Default>



  58: </FieldSwitch>



  59: </RenderPattern>



  60: </FieldType>



  61: </FieldTypes>







2. Create the logic


For the actual logics, I will create a class which inherits from SPFieldUser and I will override the 'DefaultValue' property.









   1: namespace MyProject.ContentTypes



   2:  



   3: {



   4:  



   5: public class CurrentUserField : SPFieldUser



   6: {



   7:  



   8: public CurrentUserField(SPFieldCollection fields, string fieldName, string displayname) : base(fields, fieldName, displayname){}



   9: public CurrentUserField(SPFieldCollection fields, string fieldName) : base(fields, fieldName){}



  10:  



  11: public override string DefaultValue



  12: {



  13:  



  14: get



  15: {



  16:  



  17: SPWeb web = SPContext.Current.Web;



  18:  



  19: SPUser user = web.CurrentUser;



  20:  



  21: string defaultValue = string.Format("{0};#{1}", user.ID.ToString(), user.Name);



  22:  



  23: if (this.SelectionGroup > 0)



  24: {



  25:  



  26: SPGroup group = web.Groups[this.SelectionGroup];



  27:  



  28: if ((group != null) && (group.ContainsCurrentUser))



  29:  



  30:    return defaultValue;



  31:  



  32: }



  33: else



  34: {



  35:  



  36:    return defaultValue;



  37:  



  38: }



  39:  



  40:    return string.Empty;



  41:  



  42: }



  43:  



  44: set



  45: {



  46:  



  47:    base.DefaultValue = value;



  48:  



  49: }



  50:  



  51: }



  52:  



  53: }



  54:  



  55: }








What it will do is set the current user as the default value. The setter we will leave untouched and therefore we just use the one from SPFieldUser.





3. Using the custom field


You can now use this custom field to create a custom column:









   1: <Field



   2:     Type="CurrentUserAsDefault"



   3:     DisplayName="My Custom User Field"



   4:     List="UserInfo"



   5:     ShowField="ImnName"



   6:     UserSelectionMode="0"



   7:     UserSelectionScope="0"



   8:     Group="Custom"



   9:     ID="{0ab09806-9434-4e11-bedd-d232614089b2}"



  10:     SourceID="{ac48197d-8e5a-4207-bf24-6615f4bb857f}"



  11:     StaticName="CurrentUserAsDefault"



  12:     Name="CurrentUserAsDefault"



  13: />





4. Deployment


Just create a wsp solution file and make sure the field xml is placed in the correct folder. Normally this field type should also popup in the GUI when you want to create a new site column.





5. Sidenotes


I have understood that this custom field (and possibly all custom fields) are not supported by Colligo, an offline tool for SharePoint. By not supported I mean I wasn't able to update this field. It was just read-only. Just so you know :) .

dinsdag 5 januari 2010

Exporting a SharePoint 2010 workflow into Visual Studio 2010

Hi everybody and my excuses for the long silence but the last weeks of the year and by that all the festivities, also took their tole one me :)

In this article I will show you how you can create a workflow in SharePoint Designer 2010, export it and then import it in Visual Studio 2010 for further extending.

One of the great new things in SharePoint Designer 2010 is the possibility to export created workflows to use them in Visual Studio 2010. Like this it's now much more easier for power users to design workflows and give them to a developer who can further extend this workflow in Visual Studio 2010.

1. Create a workflow in SharePoint Designer
Startup SPD and connect to your site collection. Go to 'Workflows' and click on 'Reusable workflow' to create a new reusable workflow.

Give it a name and a description and choose the content type for which this workflow will be available.

2. Design the workflow
You can now start using all the conditions and actions provided by SPD to create your workflow. I created a very simple workflow which will set the workflow status to 'Cancelled' if the current item's title field equals "Title1". Else the status will be set to 'Approved'.

You can click on 'Check for errors' if you want so you are sure that you used all components correctly.

Save the workflow. SPD will now create all the necessary files for the workflow.




3. Exporting the workflow
Now in SharePoint 2010 beta, you cannot just use the 'Save as Template' button to create a wsp file for this workflow. You would think this function works alright but when you try to import this wsp into a Visual Studio 2010 project, an error will appear saying "Parameter name - Relative path". This issue is known by Microsoft. It's due to a problem in the export function which is not handled correctly in Visual Studio.

A workaround for this, is to export the complete site as a template. To do this, click on your site collection on the left (the button with the house icon). On the top, in the ribbon, you can select 'Save as template'. This will launch the template creation aspx page. Choose a file name and template name. You don't need to 'Include Content'. Click ok to start the template creation.

After completion, click on the provided link to go to the 'user solution gallery'. From there, you can download the wsp file to your drive.

4. Importing the workflow wsp into Visual Studio 2010
Start Visual Studio and create a new SharePoint 2010 project of type 'Import Reusable Workflow'. Type in the URL to your site collection and on the next screen, point the wizard to the site template wsp file. The wizard will analyze this file and present you with a list of all the reusable workflows it could find.

Choose your new workflow and click Finish. This will load the workflow as a new project in the solution. As you can see, the template includes a feature, a package and the actual workflow including the xoml, the rules and cs code file.




Double clicking the xoml file will load the designer view. The names of the activities may not be the best chosen but at least the design itself is unchanged. Like in 2007, you can start adding activities and conditions.

The actual rules we defined in SPD, are stored in the rules file. No actual c# code is generated. Just to be clear, the workflows are based in .NET framework 3.5 and not on version 4.0.

You can now start to extend the workflow with custom code, create a wsp file and use it in your site collection.