Archives / 2009 / January
  • Licensing your servers when developing for SharePoint

    Tags: SharePoint, Visual Studio, SQL Server, Virtual Server, Windows Server 2003, Software

    A recent discussion about how the licenses of Windows, SQL and SharePoint Servers should be handled when we are developing solutions using Virtual Machines made me throw away a mail to Emma Explains Licensing. The concern was that; do we have to pay licenses for every VM or test server? That would have been insane! But I wanted to have this explained how this licensing works - a lot of you perhaps already know but I always have a hard time getting all the different licensing options and rules.

    Emma has written up a nice post on my question.

    To make her excellent explanation a bit shorter; if you are a MSDN subscriber or a Visual Studio licensee then you are fully covered. You may use as many copies on any number of devices you like of the server products for developing, testing and demonstrations. You may not use it in live production or for staging environments.

    To understand everything, please read Emma's post.

    Have a nice weekend…

  • SharePoint Community Sweden started

    Tags: Personal, SharePoint

    Yesterday SharePoint Community Sweden was launched, initiated by Andreas Kviby. This is a new community site for Swedes and those who speak Swedish about the SharePoint platform. There are a lot of great SharePoint sites and communities out there on the web, but none in Swedish. Having a great community “nearby” will enable the personal interaction to be even better and it will create a lot of interesting spin-offs.

    I’m glad to be onboard and I will put some effort into this new community and helping out new and old SharePointers as good as I can and I will try to do some blogging about interesting topics in Swedish there - once in a while I will probably double post information here and on the community site (long sentence…).

    We also have a all of Sweden's SharePoint MVP’s and a great deal of experts so I’m sure it will be a success.

    What about the Swedish SharePoint User Group then, I was asked on Twitter? I see this as a great complement to the SSUG - discussions can emerge in the community and leverage up to the SSUG meetings and the discussions can continue on the community. The SSUG target Audience (we are talking about SharePoint right) is as I see it more about deeper knowledge, but the community also offers help and space for normal SharePoint users or editors.

    See ya there…

  • Web Part Properties - part 4 - default and missing values

    Tags: SharePoint, Web Parts

    Part four of my Web Part Properties series. Now it’s time for default values and what you should do when there are values that are incorrect or missing .

    Last post discussed the .webpart file and I showed you how to do when setting up a Web Part in the Web Part Gallery with default values. Web Parts created using the SharePoint WebPart class can also define default values using the DefaultValue attribute, like this:

      1: [...]
      2: [DefaultValue("default value")]
      3: public string Text {
      4:     get;
      5:     set;
      6: }

    As I prefer to use .NET 2.0 Web Parts I have to set my default values in the .webpart file, I also gain the benefit of not having the default values hard-coded.

    Missing (default) values

    To make the Web Part experience a whole lot better for your end users make sure that you always provide default value, so that the first thing they see is not an error message or an exception.

    There are several cases when you can’t set a default value but instead want them to customize the Web Part. You should then provide an easy to understand instruction in your Web Part to tell the users to customize the Web Part.

    I prefer to have a nice message and a hyperlink that the user can click which opens up the tool pane immediately like this:


    Now all the user have to do is click the link and fill in the appropriate values.

    The code for this simple Web Part looks like this:

      1: protected override void CreateChildControls() {
      2:     if (string.IsNullOrEmpty(this.Text)) {
      3:         LiteralControl literalCtrl = new LiteralControl(
      4:             string.Format("<a id='MsoFrameworkToolpartDefmsg_{0}' href=\"javascript:MSOTlPn_ShowToolPane2Wrapper('Edit','129','{0}');\">Open the tool pane and enter a valid value.", 
      5:             this.ID));
      6:         Controls.Add(literalCtrl);
      7:     }
      8:     else {
      9:         Label lblHello = new Label();
     10:         lblHello.Text = "Hello " + this.Text;
     11:         Controls.Add(lblHello);
     12:     }
     13: }

    This code creates a hyperlink which uses one of SharePoint's built-in JavaScripts which opens the tool pane.

    That’s all for today folks.

  • Office Server downloadable Technet content

    Tags: SharePoint, Microsoft Office

    The Technet and MSDN sites are great to have when you have to look things up when developing or maintaining solutions for the Microsoft Office Servers, such as SharePoint. But I also like to have this information closer to me and have even faster access to it.

    Microsoft is providing much of the content as downloadable CHM files, which is a great feature.

    Here are a list of some of the downloadable help files

  • PerformancePoint is merged with SharePoint

    Tags: SharePoint

    Hot from the presses! Today Microsoft announced that Microsoft Office PerformancePoint Server will not be a separate product in the future, instead it will be incorporated into the Microsoft Office SharePoint Server 2007 Enterprise Edition.

    This is some great news for all of us that work with and develop BI solutions.

    Microsoft is focusing their BI solutions to three products; Excel, SharePoint and SQL Server. This is due to several factors; BI solutions have been very expensive (read PerformancePoint) and have had hard to reach out to the end-users. By incorporating PerformancePoint into SharePoint these factors will be eliminated - BI for everyone.

    As of today MOSS 2007 Enterprise customers can “deploy PerformancePoint […] at no additional cost”.

    This will be a game changer for the BI market - competitors, watch out!

    Can’t wait to see what they have done with this in SharePoint 14!

    Have a nice weekend!

  • Swedish SharePoint Bloggers

    Tags: SharePoint

    Swedish flag I thought that it would be time to look up all Swedish SharePoint bloggers, like my former colleague Johan Dewe did about a year ago, he has now left the SharePoint consultant scene, and I thought that it would be time to have a new and updated list.

    This list is compiled from my own feeds, Johan's list and some searches on the web. Since blogging nowadays isn’t the “only” way to keep up with what’s happening I’ve also included some Twitter links.

    The list only includes active bloggers, i.e. those who have written a substantial amount of SharePoint blog post the last few months or so. Unfortunately the list is not that long since Johan compiled it since most of those listed bloggers/blogs are inactive.

    The List

    Daniel Bugday - site, feed Runs the Swedish SharePoint User Group and has a great set of posts on SharePoint configuring and search.

    Tomas Elfving - site, feed Architecture and security focused.

    Daniel Karlsson - site, feed, Twitter A lot of Workflow Foundation goodies

    Andreas Kviby - site, feed (added 2009-01-22) SharePoint development in English and in Swedish

    Lise Rasmussen - site, feed Developer and customization focused

    Daniel Sörlöv - site, feed General SharePoint information and news

    Tobias Zimmergren - site, feed, Twitter Runs the Swedish SharePoint User Group and Sweden's second SharePoint MVP. Developer focused blog.

    and of course myself, Wictor Wilén - site, feed, Twitter


    Swedish SharePoint User Group

    The Swedish SharePoint User Group is run by Daniel Bugday, Tobias Zimmergren and Göran Husman (Swedens first SharePoint MVP).

    More information can be found on the user group site:

    If you feel that you or someone you know about should be listed - there must be more of us, feel free to contact me or post a comment. If you are on the list and anything is wrong, just ping me and I’ll fix it. I’ll post updates on this post on Twitter.

  • Web Part Properties - part 3 - the .webpart file

    Tags: SharePoint, Web Parts

    This is the third part of my Web Part Properties series and this post will focus on the .webpart file. Every SharePoint developer have seen it and perhaps edited it, but what is the purpose of the file and when and why should I edit it.


    The .webpart file is an XML file containing metadata about the Web Part. In previous versions of SharePoint this file had an extension of .dwp. Although these files may look similar it’s a crucial difference between those files. The .webpart file uses the schema and the .dws file uses The v2 schema is intended for Web Parts derived from the Microsoft.SharePoint.WebPartPages.WebPart class, which is the base class used for developing Web Parts for previous SharePoint versions. When developing Web Parts using the .NET 2.0 WebPart class (System.Web.UI.WebControls.WebParts.WebPart) the v3 schema must be used, see previous article on why you should use the latter.


    The .webpart file uses the following structure, with some elements left out for later posts.

    • webParts
      • webPart
        • metaData
          • type
          • importErrorMessage
        • data
          • properties
            • property

    The metadata element contains information about the Web Part; the type element must contain a name attribute which must be the full name of the Web Part class, and the importErrorMessage element contains an error message that is displayed if the import of the Web Part fails.

    The data section contains information about the default values of the Web Part properties, each default value is set using the property element. Each property element has a name attribute, a type attribute and a value; the name property must match an exposed Web Part property and the type must be the Type of the property. The type can be expressed as a fully qualified type name or one of the built-in shortcuts (string, int, bool, double, single etc). The value of the type property is the default value.

    For full reference of the schema head on over to MSDN.


    Here is a sample of a .webpart file, taken from the TweetPart in the previous Web Part Properties posts.

      1: <?xml version="1.0" encoding="utf-8"?>
      2: <webParts>
      3:   <webPart xmlns="">
      4:     <metaData>
      5:       <type name="TweetPart.TwitterWebPart, TweetPart, Version=, Culture=neutral, PublicKeyToken=cfa2cd081d8900d7" />
      6:       <importErrorMessage>Error importing Web Part</importErrorMessage>
      7:     </metaData>
      8:     <data>
      9:       <properties>
     10:         <property name="Title" type="string">TweetPart</property>
     11:         <property name="Description" type="string">Sample Web Part by Wictor Wilén</property>
     12:         <property name="ChromeState" type="chromestate">Normal</property>
     13:         <property name="AllowZoneChange" type="bool">True</property>
     14:         <property name="AllowHide" type="bool">True</property>
     15:         <property name="ExportMode" type="exportmode">NonSensitiveData</property>
     16:         <property name="TitleIconImageUrl" type="string">/_layouts/images/TweetPart/TweetPart_16.png</property>
     17:         <property name="CatalogIconImageUrl" type="string">/_layouts/images/TweetPart/TweetPart_16.png</property>
     18:         <property name="Username" type="string">wictor</property>
     19:         <property name="Mode" type="TweetPart.TwitterTimeLineMode">User</property>
     20:         <property name="TweetCount" type="int">10</property>
     21:       </properties>
     22:     </data>
     23:   </webPart>
     24: </webParts>

    As you can see the metaData is defined in row 4-7 and the default values in rows 8-23. The Web Part class we use is defined on row 5 and expressed using the full assembly name.

    If we look at the properties we notice that there are several property elements (row 10-15) that contains information on the behavior of the Web Part, these properties are almost always defined and most Web Part code generation tools, like STSDev, adds them automatically. For this part I added three custom properties, row 18-20. The second one of those uses a custom type defined in my assembly.

    Tip: Row 16 and 17 contains two system defined properties that you can use to make your Web Part look a little bit cooler by using icons. The TitleIconImageUrl points to an image that is used in the heading of your Web Part and the CatalogIconImageUrl is displayed in the Web Part Catalog.

    Note: it is not necessary to add all of your Web Part properties to the .webpart file, unless a default value is needed.

    Install and customize

    Every Web Part needs one of these .webpart files to work. To get your Web Part to work you have to register the class in the correct way and the add the .webpart file to the Web Part Gallery. This is normally done when you deploy your Web Part feature.

    If the Web Part has a lot of custom properties you can help your users by editing the .webpart file and customize the default values. Just go to the Web Part Gallery and choose to Export the Web Part. Then you just edit the file with your favorite XML editor and upload it once again to the Web Part Gallery.

    Export a Web Part

    Tip: If you don’t want to manually edit the file you can always add the Web Part to a page and then edit the properties and then use the Export menu option on the Web Part.


    I think it’s worth the time to go through your .webpart files; if you are a developer make sure that you add a good set of default values for your Web Part and as a SharePoint administrator you should help your users by setting good default values that fit your installation(s).

  • Statistics, performance and resource measuring on Windows 7

    Tags: Windows 7

    The more I use/test Windows 7, the more I get confident that this release will get Microsoft back on track. Windows Vista introduced a lot of new and interesting stuff, but was not that polished as one could expect. Service Pack 1 of Vista did take it up one notch, but not far enough.

    As the statistics nerd I am I like to know exactly what my laptop is doing, how much memory is used, which program accesses disk etc. Vista have a quite good Resource Monitor application and of course the Task Manager (even though I use Process Explorer quite a bit). Windows 7 contains some really good updates to these built-in applications.

    Task Manager

    The most hated part of the Task Manager in Vista was that you had to go trough the UAC consent procedure to see the processes from all users. But in Windows 7 (beta), the default settings of UAC are such that you only have to click the button and wait for Task Manager to start with higher privileges - no need to wait for a UAC prompt. Except for some minor changes on the Performance Tab, there are no news.

    Resource Monitor

    The Resource Monitor of Windows Vista was a typical Microsoft version 1 product - it started, did a little and gave a lot to long for. In Windows 7 this application has grown into a really interesting feature.

    You can monitor your CPU, Disk, Memory and Network usage using tables and graphs in real time. Using the filtering option you can select a process and see exactly which resources it is using, such as memory, CPU, handles etc. For example you can check exactly which files or registry handles a process is consuming or which network addresses it is talking to.

    Resource Monitor in Windows 7

    This screenshot is filtering on the sqlserver.exe process.

    Event Viewer

    The Event Viewer is the same in 7 and Vista. Only new things I noticed is that Windows 7 has a lot more Application and Service logs. I thought I check out the Diagnostics-Performance log to see some stats - but no luck. Nothing is logged here, guess this logging is omitted in the beta, and even if there was data there we are not allowed to discuss measures of Windows 7 according to the EULA.

    Performance Monitor

    The Performance Monitor (perfmon.exe) is the same as in Vista, at least what I have seen.

    Reliability Monitor

    The Reliability Monitor, maybe not known to everyone, is an application that every day grades your Windows installation on a scale from 1 to 10, 10 being the perfect machine. My Vista has a top score of 8.58 and a lowest score of 1.00, it didn’t even start at 10. My score varies a lot, probably because I often install and uninstall betas. Windows 7 have a slightly updated user interface which allows you to scale your history chart and save your history data. The new Reliability Monitor also integrated the Problem Reports and Solutions application from Windows Vista, which makes the application a lot better.


    There are a lot of improvements to Windows 7 in all areas, and I like it - I like it a lot. I really hope that everyone helps out on this beta period and reports any issues, so we all help out making a great new OS. I have reported a few already and will certainly report more once I start to use it for real.

  • Web Part Properties - part 2 - Editor Parts

    Tags: .NET, C#, SharePoint, Web Parts

    TweetPart This is the second part of the Web Part Properties series. The last post walked through the basics on how to make editable properties on a Web Part. As a sample I used a Web Part that displayed tweets from Twitter - called TweetPart.

    Using the standard approach, by marking the properties using specific attributes, we made the Web Part editable as we wanted. But the user experience, for editing, was not optimal. First of all the properties we wanted to edit was located in their own category at the bottom, not that easy to find for inexperienced/untrained users. Secondly the properties has dependencies and requires validation.

    To WebPart or WebPart

    When developing Web Parts for Windows SharePoint Services 3.0 or Microsoft Office SharePoint Server 2007 you have two different Web Part classes to choose from:

    Which one should I use when building Web Parts? WSS 3.0 supports both…

    Tip: When checking out samples for Web Parts, note which class is used. Most samples on MSDN are using the older construct.

    The first class is a part of ASP.NET 2.0 and the other one is from the Microsoft.SharePoint.dll library. The latter is there to maintain backwards compatibility with SharePoint 2003 (built upon .NET 1.1, which did not have a built-in WebPart class). I strongly recommend using the ASP.NET 2.0 WebPart, since it’s a newer construct and will probably still be used in the upcoming SharePoint 14. The ASP.NET WebPart is still in the new .NET Framework 4.0, according to the PDC 08 pre-release bits, and I doubt that Microsoft will introduce a third WebPart class. What will happen to the SharePoint WebPart class is not known (to me).

    Note: Even though the two classes share the same functionality they differ in how to create custom editing tool panes, how Web Part connections work and how their Web Part Xml definitions look like.

    The EditorPart class

    ASP.NET 2.0 contains an abstract class called EditorPart, this class is used with the ASP.NET 2.0 WebPart class to create customized tool panes. By inheriting from this control you can customize the look and functionality of the tool pane and use standard ASP.NET constructs such as auto post backs, validations etc.

    Tip: since this is standard ASP.NET 2.0 techniques you can have this running outside of SharePoint if you implement your own Web Part based web site.

    In our TweetPart sample we had a drop-down, with the different display modes. Depending on the display mode selection the two text boxes should be shown or not. To achieve this we can create a new EditorPart class and replace the auto-generated Twitter category tool pane. Standard attribute properties, with automatic tool panes, can of course be combined with EditorParts - and in this sample we will leave the count of tweets as a standard attributed property.

    First of all we create a new class which inherits from System.Web.UI.WebControls.WebParts.EditorPart. In this class you have to override two abstract methods and add the controls that you are going to use.

    Add controls

    The controls are added in the CreateChildControls method. This is where you should place most of your control logic, in editor parts, web parts etc.

    Note: Make sure you understand the ASP.NET 2.0 event model!

    I have one select list and two textboxes, representing the different web part properties here.

    protected ListBox m_lbModes;
    protected TextBox m_tbUsername;
    protected TextBox m_tbSearchString;
    protected override void CreateChildControls() {
        // Add controls here
        m_lbModes = new ListBox();
        m_tbUsername = new TextBox();
        m_tbSearchString= new TextBox();
        foreach (string mode in Enum.GetNames(typeof(TwitterTimeLineMode))) {
        this.Controls.Add(new LiteralControl("<b>Mode</b><br/>"));
        this.Controls.Add(new LiteralControl("<br/><b>Username</b><br/>"));
        this.Controls.Add(new LiteralControl("<br/><b>Search string</b><br/>"));
        this.ChildControlsCreated = true;


    The SynChanges method is used by the EditorPart to get the values from the Web Part into the Editor Part.

    public override void SyncChanges() {
        TwitterWebPart twitterWebPart = (TwitterWebPart)this.WebPartToEdit;
        if (twitterWebPart != null) {
            // get values from WebPart
            m_lbModes.SelectedValue = twitterWebPart.Mode.ToString();
            m_tbUsername.Text = twitterWebPart.Username;
            m_tbSearchString.Text = twitterWebPart.SearchText;


    The ApplyChanges method is executed when you click Ok or Apply and is used to set the property values of your Web Part. SyncChanges is always called directly after the ApplyChanges method, to make sure that the properties are in sync.

    public override bool ApplyChanges() {
        TwitterWebPart twitterWebPart = (TwitterWebPart)this.WebPartToEdit;
        if (twitterWebPart != null) {
            twitterWebPart.Mode = (TwitterTimeLineMode)Enum.Parse(typeof(TwitterTimeLineMode), m_lbModes.SelectedValue);
            twitterWebPart.SearchText = m_tbSearchString.Text;
            twitterWebPart.Username = m_tbUsername.Text;
        return true;

    Modify the WebPart class

    Now we have to tell the web part that it should use this editor part, instead of the attributed properties. First of all we want to get rid of the automatic interface for the properties, this is done by removing the Personalizable attribute.

    Note: Just removing the Personalizable attribute and none of the others (WebBrowsable etc), will still allow you to configure these properties using tools such as SharePoint Designer.

    Note: Values of properties in the editor part have precedence over automatic generated properties.

    IWebEditable interface

    Now only one thing remains and that is to expose the editor part from the web part. To do this you have to make your web part class inherit from the IWebEditable interface and implement it. Don't forget to add an Id to the EditorPart class.

    EditorPartCollection IWebEditable.CreateEditorParts() {
        // control the editorparts
        List editors = new List();
        TwitterEditorPart editorPart = new TwitterEditorPart();
        editorPart.ID = this.ID + "_editorPart";
        return new EditorPartCollection(editors);
    object IWebEditable.WebBrowsableObject {
        get { return this; }

    The CreateEditorParts method is used to tell the web part zone what editor parts you will show, in this case we only have one. But more advanced web parts may require that you have several.

    Tip: You can use the WebPartManager.Personalization status to add different editor parts. For example you can have one for the Shared scope and another for the User scope

    The WebBrowsableObject property is used to get a reference to the Web Part, just return the this object in your editor parts. This property is used by the editor part to get which web part to edit, via the WebPartToEdit method.

    The result

    If we now compile and test this web part we will have an interface that looks something like this. Now we have the edit part located at the top of the tool pane, instead of below - easier to find.


    It works, but looks awful.

    Make it more user friendly

    We only want the search string to be visible when the Search mode is selected, and the same for the username and User mode, so we have to hook up some events to this editor part. This is standard ASP.NET control programming and easily done.

    To make it look a bit nicer we reuse some SharePoint CSS classes and I also set a title of the editor part…

    protected override void CreateChildControls() {
        this.Title = "TweetPart properties";
        // Add controls here
        m_editorPanel = new Panel();
        m_editorPanel.CssClass = "ms-ToolPartSpacing";
        m_modesPanel = new Panel();            
        m_modesPanel.Controls.Add(new LiteralControl("<div class='UserSectionHead'>Mode</div>"));
        m_modesPanel.Controls.Add(new LiteralControl("<div class='UserSectionBody'><div class='UserControlGroup'><nobr>"));
        m_lbModes = new ListBox();
        m_lbModes.CssClass = "UserInput";
        m_lbModes.Width = new Unit("176px", CultureInfo.InvariantCulture);
        foreach (string mode in Enum.GetNames(typeof(TwitterTimeLineMode))) {
        m_lbModes.AutoPostBack = true;
        m_lbModes.SelectedIndexChanged += new EventHandler(m_lbModes_SelectedIndexChanged);
        m_modesPanel.Controls.Add(new LiteralControl("</nobr></div></div>"));
        m_searchPanel = new Panel();
        m_usernamePanel = new Panel();

    I use a set of Panel objects, which I hide depending on the selection in the list box. The list box has an event handler for when the selected index changes and reloads the editor part, I also made it automatically post back when the user selects anything in the list box. Check out the source (provided below) for more information.

    Now it looks like this, a whole lot nicer. In upcoming posts I will show you have to make it even one notch better, using templates and less code.


    And it works as it should. Also note that we still have the tweet count property as a automatic property, when in shared mode.

    Try it!

    If you would like the code, it’s available here but if you are interested in using the TweetPart you can download the WSP here. Visual Studio 2008 and STSDev are required to compile the code.

    Next part…

    Next part in this series, will focus on how to further improve the experience using Web Part properties and Editor Parts.

    Until next time…

  • Running SharePoint on Windows 7

    Tags: SharePoint, Windows 7

    Windows 7 beta was released into the wild today (or tomorrow if you’re not an MSDN subscriber) and I’m seriously considering running it on my main development machine. But to be able to do this I have one main requirement and that is that I can run SharePoint on it, just as I can on Vista. So after installing the beta bits on a Virtual PC I had to give it a try.

    I installed the IIS on the Windows 7 virtual pc and then tried, without any hopes, to install WSS 3.0 the normal way. Dead end, as expected:

    Dead end

    Then I took the Vista way and installed it using the tool created by Bamboo Solutions. The setup started fine and I choose to do a Basic install.

    Installing WSS on Windows 7

    When the Configuration Wizard started I received this error message, looks like it did not install the SQL Server 2005 Embedded Edition during the install.

    SSEE is obviously not working on Windows 7!?

    I download SQL Server 2008 Express (clicking next 1.000 times) and ran the SharePoint on Vista installation again this time using the Advanced mode (after an uninstall).

    This time it worked better.


    Installation took a few minutes and then I had Windows SharePoint Services 3.0 SP1 running on my Windows 7 beta installation.

    Everything worked as expected! Sweet!

    WSS on Windows 7

    I have to do some more testing with some other applications, if all turns out well then I will for sure reinstall my machine (needs a reinstall anyways, and why not have fun…).

    But, I have found some minor UI in Windows 7 bugs that I will report, as soon as Microsoft get their Windows 7 license key request app working.

    And by the way; Windows 7 runs so smooth as a Virtual PC, using only 1 GB of RAM!

    Technorati tags: , , ,

    Of course this is not a supported scenario, but my daily work is way smoother using this and I have had no problems with it so far.

  • Web Part Properties - part 1 - introduction

    Tags: .NET, C#, SharePoint, Web Parts

    I thought that I should kick off this new year with a series of posts on how to make your SharePoint Web Parts editable and how to enhance that out-of-the-box Web Part property editing combined with some tips and tricks.

    This first post may be to most of you SharePoint developers somewhat basic, but I have chosen to start from scratch here. Many of this first post topics are repeatedly asked in the MSDN development forums. The documentation in the SharePoint SDK on this topic is really bad; it just says do this and do that, never why you should do it. Often this makes developers unaware of pitfalls or possibilities.

    Note: Although I talk about SharePoint Web Parts here, most of these techniques can be used in plain ASP.NET 2.0 Web Parts also.

    Sample Web Part - TweetPart

    TweetPart I will throughout this series use a sample Web Part which reads information from Twitter and displays the tweets in the Web Part – called TweetPart. This Web Part will allow the users to choose what tweets to see; the public time line, a user time line or a Twitter search feed. Administrators are allowed to set how many tweets to display.

    All sample code are written using .NET 3.5.

    Properties of a Web Part

    A Web Part class can contain properties which can be edited in the web interface or application development environment. To be editable the property has to be marked with a set of attributes which specifies how and who can edit the property.

    Our sample Web Part needs four properties to work;

    • Display mode – an enumeration on what type of tweets to show
    • User name – a string, if the user time line mode is chosen
    • Search text – a string, if the Twitter search mode is chosen
    • Tweet Count – the number (integer) of tweets to show

    The TweetPart is a Web Part derived from the ASP.NET 2.0 WebPart class, more on this in the coming posts.

    Note: When creating editable properties for your Web Part you have to create properties that are read/write, public and called without parameters.

    I want all of these four properties to appear when someone modifies the Web Part, so I have to mark all four of these properties as WebBrowsable. This indicates to SharePoint that the property can be edited in the web the tool pane. The system will take care of how the user interface will look like; strings will be text boxes, booleans will be check boxes, enumerations will be dropdowns etc.

    Note: A common error here is that the Browsable attribute is used instead, which is used when designing components and controls for visual designers. This attribute was also used when developing Web Parts for SharePoint 2003 with the SharePoint WebPart class.

    To make the properties appear there is one more thing you have to do, you have to add the Personalizable attribute and set the personalization scope. This attribute tells the Web Part Manager that this property value is persisted. If you set the scope to User (default), then users (Members) can modify this property and if it’s set to Shared only editors (Owners) are allowed to change the property.

    Tip: If you omit this attribute, you cannot change it through the web interface, only through code or tools such as SharePoint Designer. This might be a preferred solution in some cases.

    This will make your custom tool pane look like this:

    Custom property

    Now things work, you can edit and save the value of the property and it is stored in SharePoint. But to further enhance the editing experience you should make it more user friendly.

    Make the tool pane more user friendly

    You should give it a name and a description, shown as a tooltip, to show in the editing tool pane that are more user friendly than the name of the property. Don’t rely on that your users or administrators interpret your property names correct. This is done with the WebDisplayName and WebDescription attributes.

    The tool pane has a set of categories (Appearance, Advanced and Layout) which are reserved for the base class properties. The custom properties will end up in a category called Miscellaneous, if you do not provide your own category with the Category attribute.

    Note: You cannot add properties to the reserved categories.

    So this is how we should define our custom properties, at the minimum:

    [WebDisplayName("User name")]
    [WebDescription("The Twitter Username")]
    public string Username {

    This property now has a friendly name and a description, it’s located under the Twitter category and users can change the value of it, and have their own values.

    Note: If you make changes to it in the Shared view, default if you are an admin, it will be the default values for users who have not personalized the Web Part.

    The same is done for the other three properties and now the Twitter category looks like this when editing the Web Part:

    Shared tool pane view of TweetPart

    Shared only properties and storage

    I want the Tweet count property to be edited only by those who are allowed to edit the Shared view of the web part, therefore I change the PersonalizationScope of the Personalizable attribute to Shared. This means that this property will not be displayed when editing the personal (My) view of the Web Part.

    I also add and specify the WebPartStorage attribute to Shared, this makes the Web Part store only one set of value for this property. Default is the Personal storage mode, which means that every user has it’s own property value.

    Tip: If you set the storage to Shared and personalization scope to User then every user can edit the same (shared) value.

    Now this property looks like this:

    [WebDisplayName("Tweet count")]
    [WebDescription("Number of tweets to show")]
    public int TweetCount {

    if you now open up the shared properties of the Web Part, then it looks the same as above, but if you instead go to the personal view then it looks like this:

    Personal tool pane view of TweetPart

    As you can see there is no Tweet Count property to edit, it’s only available in shared mode.

    Tip: To switch between Shared and Personal mode just add this parameter to the query string PageView=[Shared|Personal].

    Run it

    Now we have fixed the configuration of the TweetPart, let’s put it into action. As this series focuses on the editing of the properties I don not go into how I have created the actual rendering of the TweetPart using the Twitter API. It’s pretty simple and you can browse the code to see how it works.

    Public time line User time line Twitter Search
    TweetPart - public time line TweetPart - user time line TweetPart - Twitter Search

    The code

    Download the code sample below. It’s built using STSDev using Visual Studio 2008. If you prefer to just download the finished solution, it’s also available for download.

    Next step…

    Using this method of making your Web Part personalizable is fine, but there are some things that does not make it that user friendly or smooth. First of all the custom categories ends up last amongst the categories – your users might miss the properties to edit. Secondly this sample Web Part, has properties depending on each other (username is only required when using user time line and search text only when using search mode). Your own Web Parts may have more advanced dependencies or require that lists are filled during the editing.

    This is what I’m going to show during the next part of the series.

    Share your experience and stay tuned…

    Technorati tags: , ,

About Wictor...

Wictor Wilén is the Nordic Digital Workplace Lead working at Avanade. Wictor has achieved the Microsoft Certified Architect (MCA) - SharePoint 2010, Microsoft Certified Solutions Master (MCSM) - SharePoint  and Microsoft Certified Master (MCM) - SharePoint 2010 certifications. He has also been awarded Microsoft Most Valuable Professional (MVP) for seven consecutive years.

And a word from our sponsors...