Archives

Archives / 2009
  • Summing up the year of 2009 and embracing 2010

    Tags: Personal, SharePoint, Windows Mobile, Windows 7, CodePlex, SharePoint 2010

    The year of 2009 is about to close and it’s time for me to summarize this year, as I’ve done for the last few years (2006, 2007 and 2008). This year has been one of the most inspiring and exciting years for me in a very long time. I have been doing so much fun stuff this year.

    The most significant change has been starting to work for my new employer Connecta (after nine years at basically the same employer). I needed some new challenges and I now work with some really talented people from whom I learn and share so much. As you readers know, it’s all about SharePoint for me and I have done some awesome projects this year that I’m proud of and really looking forward to some SharePoint 2010 gigs. I also finally got my MCT certification and already scheduled a number of courses for next year, looking forward to meet some aspiring SharePoint students!

    Another really cool thing is that just a few weeks ago I signed a contract with Manning Publications about writing a book on SharePoint 2010, first chapter is due in a few days. This is something that I wanted to do for some time; it’s hard work but it makes me get even better – and that’s why I’m in the game. More details on the book in an upcoming post…

    Blogging

    I continued to blog about things that I’ve found interesting – not as much as I had hoped for. I’ll try to get better next year, even though focus will be on the book for the first few months. But if I take a look at the statistics it looks like it has been a great year – thank you all new followers. The most popular post this year has been:

    1. Running SharePoint on Windows 7 – one of the first things I did on Windows 7
    2. Creating SharePoint 2010 workflows with Visio 2010 – awesomeness in a box
    3. SharePoint Service Pack 2 known, found and experienced problems – there are always problems
    4. Web Part Properties - part 2 - Editor Parts – great response on this series
    5. Web Part Properties - part 3 - the .webpart file – a runner up…

    SharePoint Community

    I’ve made a big commitment to the SharePoint community this year – and I like it, I like it a lot! It has been so fun and rewarding commenting, tweeting and meeting with the incredible SharePoint community. Can’t imagine any other community that has so much fun together! Unfortunately I missed the highlight conference in Las Vegas and the chance to listen and meet the rest of you, due to the change of employer. I hope I can make it for another year.

    Here in Sweden we started the SharePointCommunity.se site to gather all SharePoint interested people and the Swedish SharePoint User Group under one umbrella and we have reached close to 500 members. The User Group here in Sweden have had some great meetings and presentations with a great number of people. Thank you again to all speakers and participants. Next year will be awesome!

    Speaking engagements

    I’ve been fortunate to have had a few presentations for the Swedish SharePoint User Group (in February two sessions and one in September) but the most fun presentations I’ve had was the one in Copenhagen at the first European SharePoint Saturday and the one at the Swedish SharePoint and Exchange Forum. It was awesome meeting all these cool people I only have had 140 characters discussions with. One of my first assignments with my new employer was a SharePoint 2010 seminar which we presented on a huge cinema screen in an almost full theatre – just loved it! I hope I will get more opportunities in 2010 do some more SharePoint love!

    Personal Projects

    As always I fiddle around with SharePoint as much as I can and I finished version 2 of ChartPart, which you can find on Codeplex. ChartPart v 1 had about 10.000 downloads and version 2 has had close to 3.000 now (and 4.000 in beta). Together with Keith Dahlby I got the SharePoint Extensions Library out – and I’ve received very good feedback on it. Two other projects also ended up on Codeplex; Windows Live ID Authentication for SharePoint and TweetPart. I will try to get these updated to support SharePoint 2010 to 100%.

    Last years predictions

    Last year I did some predictions, as I’ve done now for a couple of years. I guessed that 2009 will be a year of constant betas – and man I was right. Windows 7 betas, Office 2010 betas and SharePoint 2010 betas has been making my days wonderful/peculiar this year. I predicted that Office 14 would hit the streets – now we now that we won’t get the final bits until mid 2010. I was right about Internet Explorer 8 and Windows 7. I also predicted that Microsoft would go for more open source projects and I think they very well have lived up to that – just take a look at Codeplex where Microsoft have released a great amount of awesome projects.

    Predictions for 2010

    What about 2010 then? We all now that Microsoft is focusing everything on Office 2010 and SharePoint 2010 and they will continue grow even stronger. But I think that during the later parts of 2010 Microsoft will have something extraordinary coming in Windows Mobile 7. They must have, otherwise it’s game over for sure for Windows Mobile.

    Another thing we will see starting emerge from Redmond is a new Internet Explorer, it’s loosing market shares, so I expect some major improvements in standards compatibility and of course some new creative thinking.

    Thank you and a happy new year

    That’s all folks. The last year of this decade is over and it’s time to grab the bull by it’s horn and face a new one…

    Happy new year!

  • Improve your SharePoint 2010 applications with monitoring using SPMonitoredScope

    Tags: SharePoint 2010

    SharePoint 2010 comes equipped with a set of new tools to improve the monitoring of your custom applications, there are built-in functionality to check how long your operations take, how many SQL Server calls are done etc. All this is logged and can be visualized in the Developer Dashboard.

    Developer Dashboard

    Another good thing with this is that it’s not something that just automatically is there but you can also hook yourself into the monitoring and the actual Developer Dashboard.

    Monitoring your custom code

    There are many cases when you run into trouble in production, due to the fact that some parts are running slow or even makes your entire farm run on its knees. This can be because you are running a SQL query that takes forever, a never-ending loop or a Http request that takes just too long. In previous versions of SharePoint you either had to write custom code to log these conditions or write to the ULS logs, I even wrote my own event logging provider once to monitor the executed code.

    Monitored Scopes In SharePoint 2010 everything is executed under a so called Monitored Scope. Each scope has a set of Monitors that measures and counts calls and timings – and this is what get’s logged in the Developers Dashboard. If you take a look at the image on the right you can see that the calls are nested and each row represents a monitored scope. At the end of each scope all monitors are evaluated and if anyone of the exceeds their limits this is logged (or if you have turned on verbose logging it always is logged).

    You can very easily make your own monitored scope – and I think that you should do that from now on in all your SharePoint 2010 projects. It will help you one day!

    For example if I have a Web Part that is running an operation that could take some time, for example a web service call, I could write code like this to start my scope:

       1:  protected override void OnPreRender(EventArgs e) {
       2:      using (SPMonitoredScope monitoredScope = 
       3:             new SPMonitoredScope("Long Call")) {
       4:          longCall();
       5:      }
       6:      base.OnPreRender(e);
       7:  }
    On line 2 i create a new object of the type SPMonitoredScope and give that scope a name (“Long Call”). Inside that scope my code that might take long time is running (line 4). If the Developer Dashboard is turned on, this scope will be visible, see image below on the third line.

    image

    This is a very easy way to improve the logging of your application.

    Worth noticing is that this will not work for Sandboxed applications, they run in a separate process.

    Custom monitors

    Just logging your scopes in the developers dashboard is one thing but you also sometimes would like to make sure that you monitor how many times this code is executed. Let’s say that you are using a web service that you pay per use of, then it would be nice to monitor how many times you are querying the web service and optionally refuse usage if it exceeds your budget.

    As I said before SharePoint 2010 always adds a set of monitors to your scopes (the parent scope actually) that monitors time, SQL queries etc. And you can do the same.

    All you have to do is to create a new class and inherit from ISPScopedPerformanceMonitor and then implement that interface. To get this monitor into your scope you have to pass it as a parameter to your SPMonitoredScope constructor like this:

    using (SPMonitoredScope monitoredScope = 
           new SPMonitoredScope("Long Call", 1000, new TheMonitor())) {...}

    You can pass in as many monitors as you like.

    In the code above your custom monitor is TheMonitor and it could look like this:

       1:  public class TheMonitor: ISPScopedPerformanceMonitor{
       2:      static int s_times;
       3:      static TheMonitor() {
       4:          s_times = 0;
       5:      }
       6:      public TheMonitor() {
       7:          s_times++;
       8:      }
       9:      public void Dispose() { }
      10:   
      11:      public string Description {
      12:          get { return "The Monitor"; }
      13:      }
      14:   
      15:      public string Name {
      16:          get { return "TheMonitor"; }
      17:      }
      18:   
      19:      public string RenderValueForWeb() {
      20:          return string.Format("MONITOR: {0}",s_times);
      21:      }
      22:   
      23:      public object Value {
      24:          get { return s_times; }
      25:      }
      26:   
      27:      public bool ValueIsExcessive {
      28:          get { return s_times > 5; }
      29:      }
      30:  }

    This monitor class will count each time this monitor is called (in the constructor, line 7) and if it’s called more than 5 times the threshold value has been exceeded. (Note: this implementation will not work in production and contains no threading support). At the end of each scope, when the SPMonitoredScope is disposed it will check all monitors using the ValueIsExcessive and if that method returns true it will be logged to the ULS logs.

    This is an excerpt from a ULS log using the monitor above:

    Entering monitored scope (Long Call)
    Leaving Monitored Scope (Long Call). Execution Time=999.885180937801
    ____TheMonitor=15
    ____Execution Time=999.885180937801

    I hope this post inspired you to produce code that can be monitored more easily using the SharePoint 2010 built-in features.

    Merry Christmas to you all!

  • Swedish SharePoint User Group December 09

    Tags: SharePoint, Presentations

    Yesterday we had a Swedish SharePoint User Group meeting, hosted by Connecta (yes, my new employer). We had a new record with number of participants, over 60 interested SharePointers of all kinds showed up to listen to MVP Göran Husman, Humandata, talk about the news in SharePoint 2010 and Peter Karpinski, Microsoft Services, talk about how to do Rapid Application Development with SharePoint 2010, SharePoint Designer 2010, Visio 2010 and InfoPath 2010 and how to script you SharePoint 2010 installs. Thank you for great shows and thanks to everyone who showed up.

    I hope we can continue this trend and have as many people in each meeting and there will be meetings in other cities than Stockholm during next year.

    MVP Göran Husman Peter Karpinski
    Mattias Karlsson, MVP Tobias Zimmergren, Joakim Hägglund and Tony Reistano Peters laptop after SSD quality testing...

    I also did a short intro presentation about the survey we had earlier this autumn about the UG meetings. And from that survey I think that we will have meetings every other month or so (depending on how much people will engage). A lot of new people was interested in having a session and/or wanting to host future meetings – expect to be contacted soon for next meeting. We discussed having a meeting during Techdays 2010 in March and can hopefully squeeze one more in before that.

    Post will be updated when I have Görans and Peters presentations and Peters Awesome Install SharePoint With No Hands scripts.

  • Four interesting changes to the SharePoint Foundation 2010 API

    Tags: SharePoint 2010

    Working with SharePoint 2010 is really a joy, you stumble upon great things all the time. The API has not had any revolutionary changes to be backwards compatible; but small changes here and there, both publically visible and internally, really makes the API better than before.

    SPListItem.SPContentTypeId

    To get the Content Type Id of an SPListItem you had to first get the SPContentType from the SPListItem.ContentType and then get the Id of the content type. This method was one marked as internal in version 12, but is now marked 14. It’s those little things. There are actually a lot of previously internal properties and methods that now are public, for example the CanBeDisplayedInEditForm property on the SPField class.

    SPListCollection.TryGetList(string listTitle)

    Last year I wrote a post about this one and now it’s there. No need to encapsulate your code with try-catch blocks when trying to get a list using it’s name. TryGetList will return null if the list does not exist. Thank you guys, up there in Redmond!

    SPWebPartManager disposes the SPWeb object

    One change that is really great. When using the SPWebPartManager or the SPLimitedWebPartManager you previously had to manually dispose the SPWeb object before disposing the Web Part manager, now that’s done when disposing the SPWebPartManager or the SPLimitedWebPartManager. This will save a lot of people a lot of memory leaks.

    SPField.ListFieldUsedIn(…)

    This is an interesting one, using this method you can find out which sites and lists a specific field is used. The method returns a collection of SPFieldTemplateUsage objects, which contains Guids of the list and site Id’s. One thing that also is interesting with this one is the usage of the templated ICollection instead of an array or custom collection.

    There are of course a lot more, but these four I did find during my excavations this weekend. Have you found any favorite change except the obvious ones?

  • My SharePoint 2010 development rigs

    Tags: SharePoint 2010, VMWare, Virtual PC, Windows Server 2008 R2

    SharePoint 2010 is one greedy beast and you can’t settle with your plain old laptop; first of all you need a x64 bit environment and second of all you need some RAM. Developing for SharePoint 2007 required just a 32-bit machine, less than 4 gigs of RAM and Virtual PC and you could do most of your work without complaining to much. SharePoint 2010 requires some more thought through development environment .

    First of all you need a 64-bit platform and at least 8GB of RAM, that’s what I’m having now on my HP EliteBook 6930p. So far this machine has worked really smooth; I run Windows 7 as the main OS on it.

    Second, you can’t use Virtual PC – it’s 32 bit only! So if you like to live in the Microsoft world you have to install a Windows Server OS on your laptop of use Windows 7 VHD boot. I want to have access to my desktop applications and my main OS so I’ve walked down the VMWare path a couple of months ago and I’m currently using VMWare Workstation 7 – it’s an awesome virtualization software and I am not going back!

    Third, you need disk space – go get some USB or ESATA hard drives. If you are going to have a single setup of your SharePoint 2010 virtual machine – this may not be necessary, but if you are like me and like to be able to create snapshots, have multiple clones, non-expanding virtual disks then most probably your internal laptop disk won’t last long.

    I have two main sets of SharePoint 2010 development rigs right now:

    • A single virtual machine approach
    • A multiple virtual machine approach

    Single Machine Approach

    The single virtual machine SharePoint 2010 is an easy option; it’s a Windows Server 2008 R2 machine with 4-6GB of RAM and it runs everything from Active Directory to SQL Server to SharePoint to Visual Studio 2010. This rig is great if I want to do something quick.

    Multiple Machine Approach

    This rig is more complex, but also offers a better flexibility. VMWare Workstation offers you to create teams of virtual machines and I’ve set up a team of three servers:

    • 1 Windows Server 2008 R2 Core running Active Directory with 512 MB of RAM
    • 1 Windows Server 2008 R2 running SQL Server 2008 with 1024 MB of RAM
    • 1 Windows Server 2008 R2 running SharePoint 2010 and all apps with 4096 MB of RAM

    I find this multiple machine approach to be better performing, although it takes longer to start up and to shut down. Creating the Server Core machine with AD is probably the best thing about it, took me some time to get acquainted to the Server Core environment, but with some PowerShell love it worked like a charm.

    Only drawback with the VMWare team approach is that you can’t run your machines in Unity mode.

    I will try a third option; AD on Server Core on one machine and the rest on a single server – I think it will work great as well.

    Other machines

    I also have a Windows 7 virtual machine, that is joined to the domain and a Ubuntu Linux machine – which I’m using for demoing Office Web Applications and the SharePoint 2010 interface.

    All these setups are made with clean and compressed snapshots so that I easily can clone up a new empty environment whenever I need it.

    How is your SharePoint 2010 development environment?

  • Visual Web Parts in SharePoint 2010 cannot be Sandboxed

    Tags: Visual Studio, Web Parts, SharePoint 2010

    Visual Web Parts are a nice addition for SharePoint 2010 developers. A Visual Web Part is essentially SmartPart revisited and is one of the project types of the new SharePoint extensions for Visual Studio 2010. Sandboxing is one of the most interesting features of SharePoint 2010, especially for large scale implementations and hosting providers. The Sandboxing feature, or User Code Solution, allows you to easily upload a SharePoint feature into your farm into a special controlled environment – called a Sandbox. These Sandboxed features can be controlled by the SharePoint administrators so that they do not consume to much resources and automatically disable them if the exceed their limits. Sandboxed solutions also have severe security restrictions – you cannot access all objects or resources that you would like.

    Visual Web Parts

    The Visual Web Parts allows the developers to create and build Web Parts in a typical Microsoft manner using drag-and-drop. This will allow for better acceptance from the ASP.NET developers who are aiming for a SharePoint developers status (one notch up the ladder :-). It’s not rocket science, and all of use who knows about the excellent SmartPart are glad to see it finally supported out of the box. What happens really is that the WebPart class will load a User Control in the Web Parts CreateChildControls() method and this user control is what you can drag and drop your controls to. The Visual Studio interface nicely makes these operations seamless and takes care of all the wiring for deployment.

    The Visual Web Parts will, for good and  bad, make more developers creating Web Parts. In previous versions of SharePoint we had to manually create our Web Parts – which led to either really good code or really bad code (if you didn’t understand how ASP.NET and SharePoint really worked). But with Visual Web Parts I think we will see more ugly-code solutions rapidly developed – fortunately I see some room for some hard core Web Part development experience.

    Sandboxed Web Parts

    Since you can Sandbox your SharePoint solutions some of you by now feel pretty safe; ok, what if I get bad code – they are running in my sandbox so I just throttle the solution. This is not really the case – Visual Web Parts cannot be Sandboxed!

    Since a Visual Web Part loads a User Control (.ascx) from the SharePoint Root it needs access to run the ASP.NET method LoadControl and file system access to the ControlTemplates folder in the SharePoint Root – and this is not allowed by a Sandboxed Solution, and we are back on square on and have to use the manual Web Part creation mode.

    I think this is reasonable; for instance if we are to deploy a Sandboxed solution to SharePoint Online – I doubt that Microsoft (or any other host) would like us to deploy stuff into the SharePoint Root (unless we are on a dedicated machine) and there are several more reasons.

    Proof of Concept

    Just to show for you how it all works and how I first discovered it, and this is still asked on Twitter.

    When you create a new project in Visual Studio 2010 it asks you if this project is going to be a Sandboxed or Full-trust solution, but when you choose the Visual Web Part template the Sandboxed option is disabled, so Visual Studio 2010 already there prohibits you from creating Sandboxed Visual Web Parts.

    Visual Web Part trus level selection

    But what happens if we make a manual Visual Web Part/SmartPart? If we create an empty SharePoint Project and then choose Sandboxed solution.

    Let's play in the Sandbox

    Then we add a normal Web Part as a new project item, add a user control to the the mapped SharePoint folder ControlTemplates, this will make our solution look like this.

    Faked Visual Web Part solution

    Finally we add some code to load the user control.

    Add some code...

    And then when we try to package and deploy it we get a few errors, already here Visual Studio tells us that this can’t be done.

    Package fails

    You can even try to manually create a WSP and deploy it to SharePoint to see what happens, but I leave that exercise to you…

    I hope that you by know get the idea about why Visual Web Parts cannot be Sandboxed, and that you (unlike me) don’t try to get Visual Studio 2010 to be able to create Sandboxed Web Parts.

  • SEF 2009 Recap

    Tags: SharePoint 2010, Presentations

    SEF09 SharePoint and Exchange Forum 2009 (#SEF09) is over and I’m pretty tired but really excited. Two full days, here in Stockholm, Sweden, of SharePoint 2010 information with some awesome speakers and topics.

    SEF09 was a great conference, about 200 participants – just about the right size to have the time to chat with a lot of people and having a good time. This year the SEF conference also was the official launch of Exchange 2010 and the first larger showing of SharePoint 2010 bits in Sweden. As an extra bonus the SharePoint 2010 beta 2 bits were released during the Monday night party, and during the Tuesday sessions everybody was downloading the bits.

    I went to some really cool sessions and learned some new stuff. It was awesome meeting our international SharePoint speakers Eric Shupps, Todd Klindt, Joel Oleson, Steve Smith and Penny Coventry as well as our local cool SharePoint dudes such as Tobias Zimmergren and Niklas Goude.

    My presentation on SharePoint Insights – BI for all went well, only some minor hiccups on the tech preview bits. I hope that you who were there got inspired to make some new awesomeness in SharePoint 2010. You can find the presentation here, it’s in Swedish though.

    Also big thanks to MVP Göran Husman and Humandata and the sponsors for making this splendid conference.

    I hope to see you all next year.

    Now on with setting up some new SharePoint 2010 beta 2 machines and preparing for next demonstration, Introduction to SharePoint 2010, that I’m doing with my company (Connecta) together with AddSkills on November 27th.

    No sleep till RTM…

  • Microsoft publishes three posters on upgrading to SharePoint 2010

    Tags: SharePoint, SharePoint 2010

    Just hours before the SharePoint Conference 2009 starts in Vegas, and all information will flood out from the conference, blogs and twitter, Microsoft released three four posters that should help you in planning and updating your SharePoint 2007 installation to SharePoint 2010.

    Microsoft SharePoint Server 2010 Upgrade Approaches (added since original posting) Visually describes the different upgrade approaches

    Microsoft SharePoint Server 2010 Upgrade Planning Takes you through how to upgrade hardware and software on your servers. Shows the available upgrade paths.

    Microsoft SharePoint Server 2010 — Test Your Upgrade Process How to set up a test farm and then install your customizations, copy data and review the results.

    Microsoft SharePoint Server 2010 — Services Upgrade Perhaps the most exciting poster of them all with information on how to do an in-place upgrade of the Shared Service Providers in 2007 and how these services work in 2010.

    Service comparison of 2007 and 2010

     

    They are all a good read and should be printed by all SharePoint admins out there...

  • Last Service Pack for PerformancePoint Server 2007 is out

    Tags: SharePoint, SharePoint 2010, PerformancePoint

    The long awaited service pack for PerformancePoint Server 2007 is now released to the web - Service Pack 3. This is the last service pack for PerformancePoint Server since the PerformancePoint Server bits will from next week be turned into PerformancePoint Services in SharePoint 2010.

    PerformancePoint Server 2007

    Service Pack 3 is the last update to the standalone version of PerformancePoint, which was announced in January this year when Microsoft changed their BI strategy. After this update Microsoft will not invest any further into the 2007 version and as you hopefully are aware of - the Planning module will not exist in the upcoming 2010 version. The Planning module is instead offered as source code - now called the Financial Planning Accelerator, so that you can safely still use any investments in the Planning Module.

    You can grab the bits here: 32-bit and 64-bit. Documentation on the different upgrade scenarios can be found on Technet.

    So far the KB (975250) article on what's changed and updated is not live. Some things have popped up on Technet though, such as a updated importsecurity command.

  • Useful Delegate Controls in Windows SharePoint Services 3.0

    Tags: SharePoint

    Delegate Controls in SharePoint is a blessing when you are customizing the features and interface of SharePoint. The Delegate Controls are areas in the out-of-the-box SharePoint pages where you are allowed to inject your own controls. This is heavily used by Microsoft Office SharePoint Server 2007, which essentially is a set of features on top of Windows SharePoint Services. For example the standard WSS user information page redirects to the MOSS My Site, this redirection is done by inserting a delegate control into a specific delegate control on the userdisp.aspx page. This nifty delegate control can be used in a WSS solution when you want to create a custom profile page, without modifying any of the OOB files and easily reverts to it's original state when you deactivate the feature.

    Read more about Delegate Controls here.

    There are several places where you can inject your own code, and very few of them are documented, hence this blog post, which has lived as a OneNote page for me for some time. This is not a complete reference, but contains the most important (imho) delegate controls.

    AdditionalPageHead (allows multiple) Exists in all the default master pages and allows you to insert controls in the head element of the page.
    SmallSearchInputBox The search input box present on all pages. WSS automatically adds the searcharea.ascx control here. MOSS replaces this one with the MOSS Search input box
    GlobalSiteLink0 Exists in the default.master. MOSS uses this one to publish the variations menu
    GlobalSiteLink1 Exists in the default.master. MOSS uses this one to add the link to My Site
    GlobalSiteLink2 Exists in the default.master. MOSS uses this one to publish the My Links feature
    CentralAdminLeftNavBarTop Used in Central Admin by MOSS. Located in the top of the Quick Launch
    DelctlCreateSiteCollectionPanel Exists on the create site collection page and used by MOSS to insert the categorization of Site Collections.
    DelctlCreateSitePanel1 Same as above but when creating Sites
    DelctlProfileRedirection Exists on the userdisp.aspx page. MOSS uses this one to redirect user the the MySite.

    Do you have any favorite Delegate Controls?

  • How to export and reuse the Data View Web Part

    Tags: SharePoint, Web Parts

    Inspired by the latest SharePoint PodShow topic; The SharePoint Data View Web Part-Episode 31 and Laura Rogers post on building a permissions dashboard I just had to write this post. In the last paragraph Laura quickly mentions how you can reuse the created Data View Web Part. I think this is really important to know how to export and import this Web Part. What I don't want people to do is to fire up SharePoint Designer and create these Data View Web Parts in the production environment so that the pages get's unghosted or customized. Also when you are working with solutions packages and features to deploy your applications in environments it's necessary to know how to do this.

    Exporting

    Once you have created and finalized your Data View Web Part in your development environment or sandbox, then you can export your customizations. This is the same for all kinds of Web Parts, as long as they allow exporting. When you export a Web Part through the web interface you will get a .webpart file (read earlier published post on this), containing all the properties and metadata specified for the Web Part.

    Export... Just open the Web Part menu on the Web Part and select Export... to export the Web Part. You will be prompted for a location to save the file.

    Once you saved it you will have a nnn.webpart file on your disk, which essentially is an XML file with the metadata.

    Note: Your exported Web Part will contain the exact properties as you specified in your original location. For example if you connected to it to a list this list id will not be present in the location where you import it. So before importing it you might have to change some values in the .webpart file or at least edit the properties of the Web Part after uploading it.

    Importing to the Web Part Gallery

    If you have created a Data View Web Part that you will reuse many times throughout a Site Collection it might be worth uploading it to the Web Part Gallery. Just go to the Site Settings and then the Web Part Gallery and select Upload and upload your .webpart file. After this your Web Part is available for all authors to use.

    Importing to a page

    Advanced Web Part gallery options Importing the Web Part is not that difficult, though it can be hard to find where to do it. To import the Web Part, go to the page where you want to insert it and edit the page and then choose to add a new Web Part. Then you have to select Advanced Web Part gallery options, located in the lower right corner. When the page is re-loaded click on the Browse header and choose Import.

    Find the Import functionality... One Web Part imported

    After that you can click on Browse to select your .webpart file and finally click Upload. Once the upload is done the Web Part will appear and you can drag and drop it onto your Web Part page.

    Once it is on the page you may have to edit the properties of the Data View Web Part. You might have to change the data sources, if you for instance configured your Data View Web Part to work with a certain Site id or a List id.

    Using the Web Part in features

    You can also reuse this exported .webpart file in your SharePoint features and have them added to the Web Part gallery when activating the feature.

    Another scenario, which I've used to build dashboards and dashboard sites is that you use the SPLimitedWebPartManager to create dashboards on feature activations or certain events. The SPLimitedWebPartManager has an ImportWebPart method that takes an XmlReader as input, which essentially is your .webpart file.

    I hope you got something interesting out of this and if you haven't listened to the SharePoint PodShow about the Data View Web Part - do that immediately and understand the power of it!

  • Time for new adventures

    Tags: Personal, SharePoint, SharePoint 2010, Presentations, PerformancePoint

    I'm glad and proud to tell you all about that next month I will start a new job. I will start as a SharePoint Architect at Connecta. This is a fantastic opportunity for me and it will let me work with some of the finest SharePoint minds and developers here in Sweden as well as some really awesome customers.

    I've been working with basically the same company now since 2000, when I and two good friends founded it, iBizkit. We all came from consultancy firms working with WCM, portals and intranet solutions and had a dream of making a really good semi-product for these kind of solutions. And we did! In 2001 we integrated our product with the first version of SharePoint. We continued this integration in the upcoming versions of SharePoint, but have since the release of SharePoint 2007 focused more and more on the SharePoint platform, and I have personally lived in that world for the latest years. About two years ago, we sold the company to Pdb DataSystem, a natural step to expand and evolve the business.

    During the last years I have been headhunted (or is headhaunted?) numerous times and finally I/we found a perfect match.

    So in November I will be joining the Connecta forces and have 100% focus on SharePoint and especially the upcoming SharePoint 2010. This will allow me to grow and evolve as a SharePoint architect and developer, which is what I thrive on.

    The only downside with this is that I won't be attending the (awesome, fantastic and once-in-a-life-time) SharePoint Conference 2009 in Las Vegas. To all you SharePointers - have a good time and I'll follow the tweets and blogs from over here! I'll even drink a pint while reading them. I hope to join you on upcoming conferences...

    But if you're anxious to meet up, then head on over to the SharePoint and Exchange Forum in Sweden (SEF09) and come listen to me talk about PerformancePoint Services 2010 or come visit the free SharePoint 2010 overview event, organized by AddSkills and Connecta, where I'll show you some cool stuff that can be done with the ECM features in SharePoint 2010.

    Until next time...

  • Avoiding Xml Based SharePoint Features - Use The API Way

    Tags: SharePoint

    Developing solutions and features for SharePoint is a nightmare for all beginners, and even for the experienced SharePoint developers. If you ever have had the opportunity to create a SharePoint solution you most probably have had to make a lot of hacking in a bunch of XML files, just to build a simple feature. This is the way you have to do it, and the way taught by tutors and Microsoft, when using it with Visual Studio and no add-ins. This is the way it was, and has been, for most of us SharePoint programmers since the beta releases of SharePoint version 3.

    Nowadays you have several tools that help you out; such as Visual Studio Extensions for WSS, WSPBuilder, STSDev and more. Some have a user interface that helps you a lot; such as VSeWSS and SPVisualDev and some does not help much there; such as STSDev. But whatever tool you use you will find that you are digging yourself deep into hacking those Xml files. Unfortunately the documentation is quite poor, but we have the fantastic SharePoint bloggers and MVPs that made their code and samples available through Google, sorry Bing.

    Lots of XML

    For example when you have a site and you would like to create a custom list, you will have to define a Content Type, a list schema, a list template and a list instance and then you have a feature manifest and a solution manifest - that counts to at least five different XML files and a few different schemas. This is an awful amount of job in the beginning and I think in some cases it's a waste of time, especially if it's a custom list that only will be used once. Then we have the thing when we want to update the list or content type when it's deployed...a whole lotta XML in combination with compiled code (for example when updating Content Types)!

    I have in my recent projects abandoned the XML way (declarative/CAML) in favor of the The API way (Object Model).

    The API Way

    Almost everything that these XML files can do can be done using compiled .NET code and utilizing the SharePoint API's. Take the example above - those XML files can be replaced with a few lines of C# code. Create a Content Type, create a List, add a Content Type to the List. There are still few XML files left; the feature and solution manifests; but those two are easy to handle.

    All you have to do is put this initialization and creation code in the Feature Receivers of the Features.

    Upgrading and developing these features using the API way are also very easy and straightforward. I think it also fits better into a TDD kind of development way. If you have a list that is created through the Feature Receiver and you find that you need to add a field to that list, I just de-activates and activates that feature. This is done by a set of extension I use to create fields if they don't exist, in Lists or Content Types.

    API way - Pros

    Using the API way has several benefits:

    • As a beginner, but experienced .NET developer, it might be easier to start working with the SharePoint API
    • Mistakes are easier discovered:
      • You have to deploy and test your feature to find small mistakes in the XML
      • Some errors are detected during compilation phases
    • Debugging - yea try that with XML based features!
    • Upgrading experience is far much better (de-activate and activate)
    • Development time is most often faster, just re-register the assembly
    • Easy to staple the feature, and it's receiver, to Site Defintions
    • Testing, and TDD, is possible even outside of the SharePoint scope

    API way - Cons

    Of course there are cons of using the API way. First of all there are some things that you can't do

    • Create List Templates - for reusable lists, i.e. lists available for the end-user to create
    • Create Site Definitions
    • Create Custom Actions
    • Configure Delegate Controls

    The cons with the API way are for example:

    • Requires installation of assemblies in the GAC
      • This is in many installations prohibited due to the fact that it requires that you run in full trust.
    • I find it easier in some situations to re-use configurations created in XML files
    • When using XML definitions you can specify ID's of Content Types etc which are required in many situations, for example when you are re-using your Content Type in many farms or Site Collections.
    • Requires that you really understand how the provisioning works in SharePoint
    • Requires that you take care of the clean-up when deactivating

    Most pros and cons are of course a personal consideration, but as I said, I almost every time nowadays use the API way for my features.

    How do you develop your Features, Lists and Content Types?

    Basically I try to have a clean and simple Site Definition and then staple my features and it's receivers onto that Site Definition. It comes down to very little XML and some compiled code - very maintainable.

  • ChartPart 2.0 for SharePoint - Release To Web

    Tags: SharePoint, CodePlex

    Finally I’ve found the time to make the last work on ChartPart 2.0 for SharePoint. I have been working on and off on this release for quite some time – but now it’s here!

    ChartPart 2.0 for SharePoint is a Web Part that allows you to instantly create charts based on your existing SharePoint lists. You can make columns, bars, pies and even 3D charts.

    ChartPart 1.0 stats ChartPart version 1.0 was released last year and have had up until now close to 10.000 downloads, which I’m very proud of. I’ve received awesome feedback on the Codeplex site, on Twitter, my blog and when I met people and told them that I was the one who made it.

    ChartPart 2.0 has been in beta/RC for quite some time and has had about 4.000 downloads, which also is awesome! People have been asking me when is it due, when is it ready…and now it’s done! It’s uploaded and free to download. You can even get the source and make your own implementation.

    New Features

    ChartPart 2.0 contains a number of new features such as; better 3D charts, more customization etc. But the most interesting two things are 1) you don’t have to install it in the GAC (which several people asked med about) and 2) you can connect the ChartPart to a list view and filter the graph.

    3D graphs with SharePoint

    For a full list of features just head on over to the ChartPart 2.0 website on Codeplex.

    Another interesting feature that is new in 2.0 is that you can edit the .webpart files and set a Lock Down Mode. This allows you to restrict your users from editing certain properties, such as colors, graph types etc. This is one feature that I hope can make the ChartPart 2.0 be used in larger companies.

    I’d like to thank all the thousands of people who has helped me out by downloading ChartPart 1.0 and those who has submitted issues on Codeplex. A special thanks to those who helped me with the translation into other languages; Arash Aghajani, Frank, Alexander Bautz, Anders Dissing..

    ChartPart 2.0 in Chinese

    What are you waiting for, go download it…

  • SharePoint User Group meeting 2009-09-08 recap

    Tags: SharePoint, SharePoint 2010, Presentations, Business Intelligence, PerformancePoint

    Last night we had a SharePoint User Group Meeting here in Stockholm, Sweden. It was a great evening with a lot of attendees, thank you all for showing up. It's always fun to see new and old faces, sorry I didn't have time to talk so much with you (due to my VM's crashing just before my demos…).

    First, a big thanks to KnowIT and Jonas who provided us with a great place to host the meeting and some good food and beer!

    Two sessions were on the agenda; PowerShell and PerformancePoint.

    Niklas Goude started the meeting with some SharePoint and PowerShell love. Great session and demo. Really looking forward to see his, and Mattias Karlssons, book project come to life. You can find Niklas awesome PowerShell scripts here and Mattias automagic create your farm in Excel script here.

    The second session was held by yours truly, and I did a brief introduction to PerformancePoint 2007 with some demos on how to create dashboards and publish it to SharePoint. I'm thinking about writing up a post on the last "Dangerous Lists" demo, would you like that? You can find my presentation here. And here are the links that I referred to regarding PerformancePoint 2007 and Microsoft BI.

    And if you would like to know some more on what will happen with PerformancePoint in the upcoming 2010 release, please attend the SharePoint & Exchange Forum 2009 and my session on PerformancePoint Services 2010, that will take place in Stockholm in November.

  • New Permission Reporting Solution in SharePoint Administration Toolkit

    Tags: SharePoint

    The latest version, 4.0, of the great SharePoint Administration Toolkit has been released, read all about it in the post by the SharePoint Team. It contains a lot of interesting and great stuff that you could use for everyday usage.

    One new part of the Administration Toolkit is a SharePoint solution called Permission Reporting Solution. This is a solution package that hugely improves the permissions management of your Site Collections and Sites in SharePoint.

    Note

    The Administration Toolkit was first released about a week ago. It was quickly pulled back, since it contained some erroneous files. It's not currently available from the download site but these links will get you to it; x86 and x64.

    Note: I actually started out writing this post while trying to install the permissions reporting solution but eventually found out that the DLL that was released was not signed properly and couldn't be installed into the GAC. My guess is that's why they pulled the release back.

    Prerequisites

    Before installing the PermissionReporting solution you have to have upgraded your farm to at least the April 09 Cumulative Update and have a version that is equal or higher than 6504.

    Installation

    After installing the SharePoint Administration Toolkit you have to install the WSP package like this:

    stsadm.exe –o addsolution –filename [Full path]PermissionReporting.wsp
    
    stsadm.exe –o deploysolution –name PermissionReporting.wsp –immediate -allowgacdeployment 
    
    stsadm.exe –o activatefeature –name PermissionReporting

    The PermissionReporting.wsp is normally found in the c:\Program Files\Microsoft\SPAdministrationToolkit\PermissionReporting\ directory.

    I also had to run this command to get it working:

    stsadm.exe -o copyappbincontent

    How to use it

    When you go to Site Settings on a site you will normally find three options under Users and Permissions.

    Users and Permissions - before

    After activating the PermissionReporting feature, on the farm, you have a set of new options.

    Permission Reporting Solution installed

    It will also add new functions to lists and list items:

    Check Effective Permissions on a list or document library

     Check Effective Permissions on a document

    Check Effective Permissions

    The Check Effective Permissions is a really nice feature that allows you to check what are the effective permissions for a specific user on a list, list item or a site.

    This is how it looks like when I check the effective permissions for a specific user on a document in a document library:

    Check effective permissions on a document

    This user is member of the Visitors group and has read permissions but has been given contribute permissions directly on the object. Handy right?

    Compare Permission Sets

    When you are working out some permissions issues the Compare Permissions Sets feature is great. It's simply a tree view of your lists and sites in which you can see exactly what permissions are set on a site or a list.

    Broken Inheritance Report

    The Broken Inheritance Report feature is a report job that every 20 minutes creates XML report files of broken sites in the site collection.

    A created report

    The GrpMembership.xml file shows you what groups users are members of, Rights.xml shows you the rights set for your site collection and Permissions.xml shows you where permission inheritance has been broken and what permissions are set on those objects.

    All these XML files can be opened in Excel for easier reading.

    With SharePoint 2010 around the corner, we can hope that these features are there from start and we don't have to wait for three years before handy features like this appears :-)

  • Using custom authentication provider users in SharePoint Timer Jobs

    Tags: SharePoint

    Today I stumbled upon Yet Another SharePoint Problem (YASP) with a custom timer job. The custom timer job is supposed to synchronize some user information between site collections (on a WSS 3.0 installation). In some cases the timer job has to add users to site collections. Sounds like a no-brainer, right!

    The problem is that we are using this installation as an internet facing site and the external users are stored in AD LDS (Active Directory Lightweight Directory Services, formerly known as ADAM) and our own custom authentication provider.

    When the timer job was running it found users in one site collection and could not add them to the other site collections, using EnsureUser(). It just threw an exception and stated that it could not locate the user.

    We made sure we had the right privileges, that the timer service was running under correct account etc. Finally we hooked up the debugger and set some breakpoints in our custom authentication provider to see where it failed when it tried to resolve the users. But the Visual Studio debugger never loaded our provider assembly!

    Then it struck me; how would the OWSTimer.exe know what assembly our custom authentication provider is located in, in Central Administration you only specify the name/prefix of the forms authentication provider. The definition for the custom authentication provider is only specified in the web.config of our web application.

    So we added a configuration file to the OWSTimer.exe, called OWSTimer.exe.config and specified the authentication provider, see below. Then after a restart of the service, everything worked like a charm.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.web>
        <membership defaultProvider="TODO">
          <providers>
            <!-- Add providers here -->
          </providers>
        </membership>
      </system.web>
    </configuration>

    Everyday with SharePoint gives you new obstacles…

  • Web Parts Connections - Introduction

    Tags: .NET, SharePoint, Web Parts

    This is the first post in a series on Web Parts Connections. This spring I had a series on Web Part Properties that I think was very successful, they got some good comments and feedback and they get a lot of hits from search engines. Please help me out and evolve this new series of posts with some feedback and questions.

    What is Web Parts Connections?

    imageWeb Parts Connections allows you to connect the Web Part server controls so that they can exchange information. Web Parts can either be a consumer and/or a provider. Once you connect a consumer with a provider the consumer starts receiving data from the provider, all this is done on the server side. Web Parts can be constructed in such way that it can have several consumer and provider connection-points, i.e.it can consume or provide information from several different sources. A provider connection-point can have several consumers but a consumer connection-point can have only one provider.

    The image, to the right, illustrates in the top; one Web Part connected to another. The middle sample shows how one provider Web Part is connected to two consumer Web Parts. The sample in the bottom shows a consumer Web Part that have two consumer end-points that are connected to two different provider Web Parts.

    Note: Web Parts Connections are a part of the ASP.NET 2.0 framework

    Why Connecting Web Parts?

    When you connect Web Parts you enhance the experience for the user. You can for example have one Web Part containing a list of items and let that one act as a provider and then have a consumer Web Part that shows detailed information of the item selected in the provider Web Parts.

    In SharePoint most of the default Web Parts are either consumers or providers. For example, with some easy clicks in the interface you can connect lists and make one a consumer and the other provider.

    Connecting Custom Lists Filtering

    The image above shows two custom lists that are connected. The Regions list contains the names of the regions, used in the Sales list. With this simple action we have built a Filter Web Part to filter our Sales list. More about Filter Web Parts later on in the series. The left image shows how you make the actual connection and the image to the right shows you how you can filter the Sales list using the radio buttons on the Regions list.

    I've been working a lot building dashboards and applications for BI-solutions and similar. Using connected Web Parts have both made the end-user experience a whole lot better (and more good looking) as well as the development of the dashboards.

    This was an introduction to Web Parts Connections, the next part will be up in a couple of days.

    Until next time.

  • SharePoint Saturday Copenhagen - Thank you!

    Tags: SharePoint, Presentations

    SharePoint Saturday Copenhagen is over after an awesome Saturday in Copenhagen. Thank you all organizers, attendees, speakers and sponsors, I had a blast. I will definitely attend more SharePoint Saturdays when I can. These kind of events really are special; everyone attending are there because they really love working with SharePoint, on a Saturday, when the sun is shining outside, for free…

    You can find my presentation SharePoint Online and Windows Azure - better together here and the solution that I used for the demo here.

    Until next time…

  • Fix the SharePoint DCOM 10016 error on Windows Server 2008 R2

    Tags: SharePoint, Security, Windows Server 2003, Windows Server 2008, Windows Server 2008 R2

    If you have been installing SharePoint you have probably also seen and fixed the DCOM 10016 error. This error occurs in the event log when the SharePoint service accounts doesn't have the necessary permissions (Local Activation to the IIS WAMREG admin service). Your farm will still function, but your event log will be cluttered.

    On a Windows Server 2003 or Windows Server 2008 machine you would just fire up the dcomcnfg utility (with elevated privileges) and enable Local Activation for your domain account.

    But for Windows Server 2008 R2 (and Windows 7, since they share the same core) you cannot do this, the property dialog is all disabled due to permission restrictions. It doesn't matter if you are logged in as an administrator or using elevated privileges. The change is probably due to some new security improvements.

    DCOMCNG - all disabled

    The reason for it being disabled is that this dialog is mapped to a key in the registry which the Trusted Installer is owner of and everyone else only has read permissions. The key used by the IIS WAMREG admin is:

    HKEY_CLASSES_ROOT\AppID\{61738644-F196-11D0-9953-00C04FD919C1}

    Registry permissions on R2 Registry permissions on R1

    Image on the left shows the default permissions for Windows Server 2008 R2 and on the right the default settings for Windows Server 2008.

    To be able to change the Launch and Activation Permissions with dcomcnfg you have to change the ownership if this key. Start the registry editor (regedit), find the key, click Advanced in the Permissions dialog of this key and select the Owner tab. Now change the owner of the key to the administrators group for example, then set full control to the administrators group. Make sure not to change the permissions for the TrustedInstaller.

    Now you have to restart the dcomcnfg application and once find the IIS WAMREG application and then set the Launch and Activation settings that you need to get rid of the DCOM 10016 error.

    Unlocked!

    Good luck!

    WARNING: Changing the registry may seriously damage your server. All is on your own risk!

  • SharePoint Saturday Copenhagen - I'll be there!

    Tags: SharePoint, Presentations

    SharePoint Saturday is a free informational and educational event that has been held over-there in US several times with a huge success the last year and it is now coming to Europe and Copenhagen, Denmark to be more specific. A SharePoint Saturday is an event for anyone interested in SharePoint and who like to meet similar-minded people and listen to SharePoint professionals and celebrities.

    I'm going to be there - it will be a blast! I will do a presentation called SharePoint Online and Windows Azure - better together! And I will of course listen to all the other really cool people showing up such as SharePoint MVP's and gurus.

    If you would like to come, did I mention it's free, then head on over to http://www.sharepointsaturday.org/copenhagen/ and register yourself! I look forward to meeting you all!

  • Use the LayoutsPageBase class when creating SharePoint Application Pages

    Tags: SharePoint

    In most custom SharePoint solution projects you will have to create your own Application Pages, Web Part Pages or other ASP.NET pages to fulfill your requirements. If you are coming from the ASP.NET world you are pretty used to building web forms and similar .aspx pages. Your pages will most of the times then be derived from the System.Web.UI.Page class, but when working with SharePoint you should not use this class as a base.

    Instead you should always use one of the following base classes provided in the Microsoft SharePoint APIs.

    LayoutsPageBase class

    The LayoutsPageBase (in Microsoft.SharePoint.WebControls) class is the most common class to derive application pages from. This is a very basic class but makes your life a whole lot easier in the SharePoint world.

    Pages derived from this class should always reside in the _layouts folder. These pages are called Application Pages (or _layouts pages) and are allowed to contain custom code, compared to Content Pages which reside in SharePoint (such as Web Part Pages). These pages cannot contain customizable Web Parts or Web Part Zones. Creating Content Pages is another story.

    The advantages with using the LayoutsPageBase as your base class is that you can easily access the current SharePoint Site or Site Collection with the built-in properties and control the security of the application page.

    Access the SharePoint objects

    With the LayoutsPageBase class you can use the built-in properties for the Site and Web to access the current Site Collection or Site (both these properties are derived from the UnsecuredLayoutsPageBase class, see below) or use the SPContext class to access the current site and web.

    Stop long running operations

    You have most certainly created some pages that creates reports or similar that may take a long time to generate and consumes server resources. Some times it takes so long that the user shut downs the web browser and go drink a cup of coffee instead. If you have those kind of pages you should use the StopRequestIfClientIsNotValid method. This method ends the request if the client is no longer connected to the page and saves you of some CPU cycles. On the other hand, if you have these kind of pages - think over and use the SPLongOperation class to inform the user that it will take a while.

    The page will also automatically call this method in several of the page events, such as OnLoad and Render.

    Security in the Application Page

    The LayoutsPageBase class contains a virtual property called RightsRequired, this property can be used to programatically set which rights (on the current Site) that are required to use the application page. By default the rights are checked at the end of the OnLoadComplete, but using the RightsCheckModes property you can disable the check or perform it in OnPreInit instead.

    There are also a property called RequireSiteAdministrator that can be overridden to make sure that the user is site administrator.

    Exit from the Application Page

    If you are creating an application page the uses the ButtonSection control template you will have a Cancel button. The target of this Cancel button is controlled using the PageToRedirectOnCancel property. Just override the property and return a string containing the target of your cancel page.

    UnsecuredLayoutsPageBase class

    The LayoutsPageBase class derives from the UnsecuredLayoutsPageBase class, which derives from the System.Web.UI.Page. Only derive from this one directly if you need anonymous and non-authenticated users to access your application page. Most of the methods and properties used in the LayoutsPageBase class comes from this class.

    For example the Login Page uses this one as a base.

    This was a quick post to get you started with creating custom application pages in SharePoint. So what are you waiting for...

  • Creating SharePoint 2010 workflows with Visio 2010

    Tags: Microsoft Office, SharePoint 2010

    The new Office 2010 clients have been released as a Technical Preview and I'm fortunate to get my hands on them and free to talk about them. The new clients are awesome!

    Visio is one of the applications from the Office suite that I use on a daily basis to design, model and draw diagrams, workflows and solutions. Visio 2010 has gotten a really nice facelift and a whole new set of features. The Ribbon has been one of the things I really missed in the 2007 release and the SharePoint integration, that can be seen in the Sneak Peak, looks awesome!

    Building workflows for SharePoint has mainly been done using either SharePoint Designer 2007 (dull and not reusable) or Visual Studio (complex). SharePoint 2010 will use the new Windows Workflow Foundation (4.0) and rumors say that SharePoint Designer 2010 and Visual Studio 2010 has even better support for building workflows.

    Microsoft SharePoint Workflow Visio Template Visio 2010 comes with a brand new template; Microsoft SharePoint Workflow. Using this template you can design your workflow and then export it. This exported file can then be imported to SharePoint Designer 2010 or Visual Studio 2010 (just a guess - Visual Studio 2010 with SharePoint 2010 dev tools is not yet publically available). Another guess is that you can export the workflows from SharePoint Designer 2010 and import them into Visio for better visualization or documentation of the workflow.

    You can design your SharePoint workflow just as you would design any other workflow using Visio, drag and drop and make a nice layout. This is great when you are making a specification for your SharePoint solution. Far better is that the ones responsible for the actual workflow or processes can design the workflows for you without knowing a bit about SharePoint, just some basic knowledge of Visio.

    Workflow sample

    Once you're done with your workflow you can validate it, so that you have not missed any branches or any mandatory information. Then you save it as a Visio or file or better export it as a Visio Workflow Interchange (.vwi file).

    In Visio you can only make the actual design of the workflow, not the configuration which is done in SharePoint Designer 2010.

    The .vwi file is a zip compressed file containing the XOML files (XAML files for workflows) and some Visio information. This XOML file can of course be opened in Visual Studio for editing, you just require the SharePoint 2010 dlls :-)

    What I have not been able to test yet is the import in SharePoint Designer 2010, since it requires SharePoint 2010.

    I will start using it immediately for designing workflows!

  • Use Windows Azure as your SharePoint Records Center

    Tags: SharePoint, Windows Azure

    Introduction

    Microsoft SharePoint contains functionality for Records Management, which essentially is a storage for documents that you would like to store and manage in a separate records center to meet certain legal or other requirements or just to make backups of certain document revisions. To be able to create a Records Center you need to have Microsoft Office SharePoint Server 2007 (MOSS). On the other hand you only need Windows SharePoint Services 3.0 (WSS) to send documents to the Records Center.

    You configure the Records Center connection in the Central Administration. When connecting to the Records Center all you do is specify a Url to a web service and a name. The Url points to a special MOSS web service called OfficialFile.asmx (http://server/_vti_bin/OfficialFile.asmx). Your receiving Records Center server does not have to be in the same farm as from where you send the document (and it should probably not be either). Another thing is that the receiving Records Center does not even have to be a SharePoint server. It's just a web service and we can implement it anywhere we like.

    I thought why not implement it using the Windows Azure technologies? This would be a great solution when you do not want to invest in either MOSS or a new MOSS farm, when you really want your important documents to be stored on a completely different physical location etc.

    Requirements

    For this exercise I have used Visual Studio 2008, Windows Azure SDK and the Windows Azure Visual Studio plugin. You also need to have access tokens/claims to the Windows Azure beta.

    The Mission

    To create our Cloud Records Center we need to create an Azure Web Role, which hosts the Records Management web service and a page to show our documents and some other logic. Our Records Center should also be able to handle some very basic record routing and metadata.

    Note: the complete sample code can be downloaded here.

    Create the Web Role project

    Create a Web Cloud Service First of all we need to fire up Visual Studio 2008 with the plugins as above and create a new Web Cloud Service called AzureRecordsCenter.

    Create the data storage

    Without digging to deep into the Windows Azure table and blob storage I just briefly describe how the storage is implemented. This sample has two tables; one for storing the routings and one to store information about the submitted documents. The blob storage is used to store the actual documents. The Windows Azure SDK contains a sample StorageClient which makes it really easy to work with the data, and this sample is used as a reference in the application.

    Storage class diagram

    I've created two classes to represent the tables; DocumentEntity and RecordRoutingEntity and a class that handles the actual data services called DataContext. The data classes has a primary key property combination; PartitionKey and RowKey (inherited from TableStorageEntity from the StorageClient sample) - I only use the PartitionKey and RowKey has a static value.

    The RecordRoutingEntity is used to store the name and optional description of the record routings and the DocumentEntity contains some information about the documents and a reference (Guid) to the name of the blob.

    Take a look at the code for more information.

    To be able to add routings the default.aspx was modified and I also added a Setup.aspx page which creates the tables in the Windows Azure storage.

    The OfficialFile.asmx web service

    To be able to create our own Cloud Records Center we have to implement the same web service as MOSS offers - the OfficialFile.asmx. The .NET Framework SDK contains a great tool, wsdl.exe, for converting a WSDL from a web service into a server side interface. Use the Url to the web service from any of your MOSS servers.

       1: wsdl /out:IRecordsRepositorySoap.cs /n:AzureRecordsCenter_WebRole /serverinterface http://xxxxx/_vti_bin/OfficialFile.asmx?WSDL

    This will generate an IRecordsRepositorySoap.cs file containing the correct interface for the records management web service. So we create a new Web Service in our project, called OfficialFile.asmx, add our generated interface file to the solution and then we let this new web service implement the interface we extracted from the WSDL. The namespace for the web service is also changed into the same namespace as the official OfficialFile.asmx use.

       1: [WebService(Namespace = "http://schemas.microsoft.com/sharepoint/soap/recordsrepository/")]
       2: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
       3: [System.ComponentModel.ToolboxItem(false)]    
       4: public class OfficialFile : System.Web.Services.WebService, IRecordsRepositorySoap 
       5: {
       6: ...
       7: }

    This interface now contains four methods:

    The three latter are pretty straight forward and the SubmitFile method receives the file, the route to use (the name of the Content Type) and all metadata of the file. First it creates the document entry in the Document table and the uploads the blob. My sample also validates that there is a valid route and otherwise returns an error.

    Put it in the cloud

    To get it all to work you have to create a new Hosted Service in the Windows Azure Developers Portal and then you have to create a Storage Account. Modify the Service Configuration of your cloud service to match your storage account.

    Build the solution and use the Publish function from Visual Studio to publish your application to the cloud and put it in either the Staging or Production environment and wait for it to start (this may take a while).

    Azure Records Center is running

    Swapping between staging and production has been quite troublesome and results in an error or timeout quite often for me the last few days.

    Browse to your cloud web application and add a route or two. The name of the route should correspond to the name of your Content Types.

    Azure Records Center

    In the image above I have added a new Route called Document.

    Configure SharePoint

    Records center configuration in Central Administration To be able to send the documents from SharePoint to our cloud records center, all we have to do is go to Central Administration of your SharePoint farm and configure the Records Center Connection, found under Application Management/External Service Connections/Records Center. Enter the Url of your hosted service and append the OfficialFile.asmx path (http://nnnn.cloudapp.net/OfficialFile.asmx) and enter a name for your Records Center connection.

    image

    Record it!

    To try it out, just head on over to a Document Library and add a document and the open up the list item menu and choose Send To - Azure Records Center (in my case).

    Send it to Windows Azure

    Wait for the file to be uploaded to your Cloud Records Center.

    Document uploaded successfully

    Then head back to your Azure web application and load the default page. You should now be able to see the document there and click on the link to bring it up.

    There it is!

    If you upload a document of a content type that is not registered as a route, then you should get an error.

    Conclusions

    Now you know how to build a simple Records Center utilizing Windows Azure and known .NET techniques. This is in no way limited to Windows Azure, you can host it or similar solutions anywhere on any platform whenever you want.

    If you want to have a Records Center and don't want to buy a MOSS license, then this solution can be a good fit.

    Disclaimer

    The provided code is in no way ready for production. It has no good exception handling nor security checks. It is provided as a sample for you to look at if you need to get started with either building a Records Center or just want to learn something about Windows Azure.

    Have a nice summer!

  • SharePoint Virtualization Survey - results

    Tags: SharePoint, Virtual Server, Hardware, Virtual PC

    About two months ago I tried to reach out to the SharePoint community with a small survey on how Virtualization is used with SharePoint. The survey was primarily for my own interest to benchmark what others are doing, but I also thought that I should share this with everyone. SharePoint and Virtualization is an interesting piece of discussion; some despise it and some love it. For more information on SharePoint and virtualization read this great article from SharePointMagazine.net.

    And now the results

    All but one answering this survey said that they were using virtualization in their SharePoint environment. Not that surprising - I guess that if you don't virtualize then you do not even bother to look at the survey.

    Virtualization technology

    Since this survey did not specify if it was for production, test, staging or development the answers on what virtualization technology that was used was quite spread. Microsoft Hyper-V and VMWare ESX Server was the two products that most survey participants used. Not surprisingly was Microsoft Virtual PC right behind those two.

    image

    What is virtualized?

    Almost everyone (95.7%) is virtualizing their development environment and half (50%) of the survey participants is virtualizing their production environment. This was a bit higher than I expected.

    image

    But what is virtualized then? The Web Front End was the clear "winner" with the Query service as a runner up. A quite high number of respondents answered that they were virtualizing the database role (73,9%) but only half of them could really recommend it (37,2%). The Excel Services role was something that about half of the participants virtualized (47,8%) and recommended for virtualiztion (44,2%).

    image

    The majority did not recommend virtualizing the database role (80%) nor the Index role (43,3%).

    Satisfaction!

    Almost everyone was very satisfied (40%) or satisfied (53%) with virtualizing their SharePoint environments and only a few were dissatisfied (7%). 98% of the respondents do recommend virtualizing SharePoint.

    Why?

    One thing that I really wanted to find out was why SharePoint is virtualized and here are what the survey participants thought:

      Agrees Neutral Does not agree
    Lower hardware cost 82% 14% 5%
    Lower license costs 21% 47% 33%
    Lower maintenance costs 62% 29% 9%
    Better performance 7% 52% 40%
    Improves scalability 64% 24% 12%
    Improved security 27% 56% 17%
    Improved redundancy 60% 36% 5%
    Safe backup 55% 31% 14%
    Simplifies development 86% 14% 0%
    Simplifies deployment 73% 20% 7%
    Positive effect on the environment 74% 26% 0%

    Simplified development and lower hardware costs was the two ones that was quite expected. When looking at the license costs most people were neutral or thought that the license costs were higher with virtualization, probably due to the fact that you might need more (virtual) servers to have the same performance (only 7% thought performance was better with virtualization).

    The numbers speaks for themselves and I do like that 74% also thinks that this has a positive effect on the environment.

    Any other comments on this survey, pleas post a comment below.

    Have a nice summer

  • 70-630 passed! Do you really call this a certification!

    Tags: SharePoint

    Just in time for next version of SharePoint to arrive I just completed the final certification exam for SharePoint 2007, the 70-630 Microsoft Office SharePoint Server 2007, Configuring. As always I did think that it should be some tricky questions or problems to solve in the exam, I even installed a MOSS RTM last night just to walk through the admin interfaces before the infrastructure upgrade. But to my disappointment this certification was by no means any challenge. This was by far the easiest of the four exams.

    After taking the two developer (70-541 and 70-540) and the configuring exams (70-631 and now 70-630) I really think that Microsoft has failed in creating exams that has any kind of value as a certification. To have some kind of validity on these exams/certifications they should give you a challenge, it should be (must be) hard to pass them. I really hope that Microsoft totally changes how these certifications are outlined and put together for the certifications of the next version of SharePoint. Passing these exams today says nothing (and do not even mention if you failed them). Make the questions into more troubleshooting, especially the configuring exams, have questions on the best practices, make some kind of scenario with linked questions and perhaps even some kind of virtual lab I understand that all problems and best practices are not "invented" when the exams hits the streets, but why not having a level 2 exam coming a year or so later, that has some higher status.

    Last week at the SharePoint User Group meeting we had a session with Sweden's first SharePoint Master who told us about the Master certification program - and that is what I call certification. Ok, not everyone will be or even have the chance to be a Master (read Spencer Harbars post) and I do not want the standard exams to be this hard/impossible. Those who passes the MCM are not only Masters they are immortals!

    Anyways, I know have the four ones and really looking forward to being acquainted with SharePoint 2010. Not all was bad with these exams though, they made me read through a set of books, making some labs on my own and with that I learned a whole lot.

  • Six ways to store settings in SharePoint

    Tags: SharePoint

    When developing applications or custom solutions for SharePoint you will on several occasions have to store settings for you application of some kind. When developing database driven or other custom solutions you easily create a database table or make the settings in app/web.config file. You can of course use these approaches when developing for SharePoint, but there are some things to consider when doing this. This post will outline some approaches you can use to store your settings.

    What I mean with application or solution settings is some kind of settings that you need for you application to work, such as a Url to a web service or a username and password. These settings are normally only editable by administrators, which requires you to have some security plans, and you need an interface to edit the settings.

    Worth to have in mind is that SharePoint can span multiple servers and web applications, it also has the Site Collection and Site scopes which might need different settings if your application runs on several places.

    Using a SharePoint List

    Creating a database table for storing settings is not the best way in a SharePoint solution - you would use a SharePoint list for this instead. This is the easiest way. Creating a custom list with Title and a Value allows you to store all your settings in one place. There is no need to create a user interface, since you use out-of-the-box functionality and you can secure the list by using permissions on it. The drawback is you need some information (read other setting) that tells you where this list is located, so you're back on square one.

    Using web.config

    Using web.config is another way to store your settings. It's easy to store information in the appSettings element using a key/value combo. The .NET Framework have built-in functionality to read these settings and SharePoint has some (not so good working) features to deploy the settings in your farm with the SPWebConfigModification class. This approach can only be applied if your settings are web-application wide and you either deploy the settings with the SharePoint object model, which can be quite cumbersome, or manually edit the web.config file on all WFE's.

    Using the SPWeb object

    The SPWeb object has a Properties property that is persistable StringDictionary stored on the Site (SPWeb) level. This is a perfect solution when you have to store Site specific settings and have the setting available over all your farm. The Properties property is used like this:

       1: SPWeb  web = ...;
       2: // set the value
       3: web.Properties["TheSetting"] = "the value";
       4: // update the value
       5: web.Properties.Update();
       6: // get the value
       7: string val = web.Properties["TheSetting"];

    Easy and simple when you have to store key/value combinations, but not so good when you have to store more complex objects, then you have to make some Xml serialization/deseralization yourself.

    The permissions in this case is controlled by the MangedWeb permission and you have to build your custom interface.

    Using the SPSite object

    The SPSite object does not have any Properties property like the SPWeb object, so if you have to store your settings on the Site Collection level you just use the SPSite.RootWeb SPWeb object and use the approach above.

    Using SPWebApplication Properties

    If you need to store your settings on the Web Application level and you don't to make changes to the web.config, then you can use the SPWebApplication object. The SPWebApplication object inherits from the SPPersistedObject which has a Properties property. This property is a HashTable so you can store key/value combos here. The value can be of any type, as long as it can be serialized.

       1: SPWebApplication webApp = ...
       2: object obj = ...
       3: // set value
       4: webApp.Add("TheSetting", obj);
       5: // persist it
       6: webApp.Update();

    This approach requires the user to be farm administrator and you have to build your own interface.

    Using custom SPPersistedObjects

    Perhaps the best (imho) way to store settings for your web application is to use custom SPPersistedObjects. This approach is very handy when you have to store multiple settings and more complex values. You create your own class that derives from the SPPersistedObject and add your settings as properties to the class and marks them with the Persisted attribute.

       1: public class TheSettings: SPPersistedObject {
       2:     public TheSettings() {}
       3:  
       4:     public TheSettings(string name, SPPersistedObject parent, Guid id) 
       5:         : base(name, parent, id) { }
       6:     
       7:     [Persisted]
       8:     public string WebServiceUrl;
       9: }

    Then you use the SPWebApplication GetChild method to retrieve your settings.

       1: TheSettings settigs = webApplication
       2:     .GetChild<TheSettings>("theSettings");

    I usually add two static methods to my settings class for easy creating and retrieval of settings:

       1: public static TheSettings GetSettings(SPWebApplication webApplication) {
       2:     TheSettings settings = webApplication.GetChild<TheSettings>("theSettings");
       3:     if(settings == null) {
       4:         return TheSettings.CreateNew(webApplication);
       5:     }
       6:     return settings;
       7: }
       8: public static TheSettings CreateNew(SPWebApplication webApplication) {
       9:    return new TheSettings("theSettings",  webApplication, Guid.NewGuid());
      10: }

    This also requires farm administrator to persist and you have to create an interface

    That's it

    There you have it; six different ways to store and retrieve settings for you SharePoint custom application. When to use which one is up to you and your needs.

    What are you preferred ways or do you have any other suggestions or additions?

  • New release for SPExLib with SharePoint Linq extensions

    Tags: SharePoint

    I'm really glad that we have managed to get a really nice release of the SharePoint Extensions Lib, SPExLib, out. This brand new release (12.0.0.0) has significantly been improved since the first release a couple of weeks ago.

    Keith Dahlby has made some really nice Linq extensions for SharePoint which is available in this release. These extensions are also IDisposable safe when using on SPWeb and SPSite collections.

    By referencing the SPExLib.dll and include the namespaces you can easily write code like this (taken directly from one of my current projects):

       1: SPList regions = web.Lists["Regions"];         
       2: regions.GetItems("<Where><Eq><FieldRef Name='Customer'/><Value Type='Lookup'>{0}</Value></Eq></Where>"
       3:                     .FormatWith(lookupValue)
       4:                 )
       5:            .ForEach<SPListItem>(
       6:                     item => ddlRegion.Items.Add(new ListItem(item["Title"].ToString(), item.ID.ToString()))
       7:             );

    As you can see the sample uses a number of extension methods; SPList.GetItems() can accept a CAML query directly, System.String has a FormatWith method, the SPListItemCollection has a ForEach method.

    Download it and try it out, you will find yourself more productive!

    Have a nice weekend.

  • SharePoint Online updated

    Tags: SharePoint

    Microsoft has updated SharePoint Online with a patch that resolves the bug that prohibited you from getting the service descriptions from the web services, that I previously described.

    This means that you now can use Visual Studio or SharePoint Designer (or any other tool that you like) to connect to the SharePoint Online web services and code away, instead of going to some local instance to get the descriptions.

    Does anybody know where the Microsoft Online team posts all updates/changes to the BPOS? I got this information from Troy (from the BPOS team) commenting on my post.

  • SharePoint Service Pack 2 known, found and experienced problems

    Tags: SharePoint

    Installing a new service pack onto a server product is not just firing up the installer and hit next->next->finish. You should carefully read through the documentation and test it thoroughly. Service Pack 2 for SharePoint has been long awaited and I’ve seen people the last 24 hours installing it like madness just wanting to get their hands on the new features/updates. I did also install it just minutes after it was released (on my dev machine that is being reinstalled any hour now, when Windows 7 RC is out). 

    Andrew Connell said it well in a tweet just recently: “I’s watching everyone else install #sharepoint SP2 to see if there are issues (ala IU's AAM fiasco)... thanks in advance guys :)”

    Twitter is one nice source of real-time update on what is happening right now on just about everything, especially when it comes to #SharePoint. I’ve collected some of the known, found and discovered problems with Service Pack 2 for Windows SharePoint Services 3.0 and Office SharePoint Server 2007.

    Have you experienced any other troubles, I’ll gladly update the list!

    If you’re anxious to install it, here is a great guide by Shane Young.

  • Introducing SharePoint Extensions Lib

    Tags: SharePoint

    I've had an idea for some time to gather all mine and others nifty extension, utility and helper methods into a shared library so that these can be reused in different projects and I finally got my act together and created a new project on Codeplex called SharePoint Extensions Lib, http://spexlib.codeplex.com/, SPExLib.

    SharePoint Extensions Lib

    This is a library filled with extension methods to the SharePoint object model and to the Microsoft.NET 3.5 SP1 classes as well as some helper classes. All you have to do is reference it in your solution and add the using SPExLib.Extensions statement to your code and you are ready to go.

    The goal with this project is to make SharePoint programming easier and to fill in the gaps left out in the standard SharePoint APIs.

    Version 1.0.0.0

    This first version contains extension methods such as:

    • SPWeb.ListExists() - checks if a list exists in a site
    • SPList.ViewExists() - checks if a list contains a specific view
    • SPListItem.Contains() - checks if a list item contains a specific field
    • SPListItemCollection.FindByField() - returns all items with a certain value to a specific field
    • Extensions to the XElement and XmlNode objects
    • A set of classes to make creation of WebParts with EditorParts easier to create
    • and more

    New versions will be released as soon as we have some new and cool extensions.

    Contributions - I want you

    I really would like to see contributions to this library, so feel free to contact me or write suggestions on the Codeplex discussions page. I know that you are sitting on really good stuff out there.

    If you have similar or better implementations that the ones already there, please feel free to show me a better implementation. Let's make this first class.

    You can also get the source and check it out and borrow some methods if you like. SPExLib is licensed under Ms-PL.

  • Virtualizing XP applications using Windows 7

    Tags: Visual Studio, Windows XP, Windows 7, Virtual PC

    Windows 7 has an upgrade to Virtual PC which allows you to run Windows XP applications virtualized on your Windows 7, without having to run the whole desktop running.

    I still have to use Visual Studio 2003 to support some old good applications including SharePoint 2003 apps. So I have used a Windows XP virtual machine to run it, but now I can fire up Visual Studio 2003 directly from my Start menu in Windows 7. As most of you know, you can't install VS2003 on a Vista or Windows 7 machine, and I don't even want it there either.

    It's also great for having Internet Explorer 6, 7 and 8 on the same machine!

    Here are some pictures of the Windows XP Mode features.

    Visual Studio 2003 running on Windows 7 using Windows XP mode

    Visual Studio 2003 running on Windows 7 using Windows XP mode

    Published XP Mode apps

    The published Windows XP applications in the Windows 7 start menu.

    image

    The Windows XP notification icons appear in the Windows 7 notification area. Note  the Windows Update and Windows Security Alert icons. I thought this was really cool.

  • Prohibit your users from selecting No Quota when creating Site Collections

    Tags: SharePoint

    I've been annoyed for some time at that you cannot prohibit your users from selecting "No Quota" when creating Site Collections. Yes, you can set a default to use but the "No Quota" option is still there. Most probably you have some governance plan or similar that says that you should set quotas when creating Site Collections, but you know that sometimes you forget or somebody doesn't even care or know what setting No Quota implies.

    No Quota when creating a Site Collection

    Create a feature that removes the No Quota option

    But, hey - I love to write code and I was sure that you could get around it in someway. First option I thought of was creating a custom Create Site Collection page (_admin/createsite.aspx), but that's not so beautiful right? But SharePoint has some nifty constructs that allow you to insert custom controls in most pages, called Delegate Controls. The create site collection page has one of those, so I wrote up a small control that uses the delegate control called CreateSiteCollectionPanel1 in the page I deployed to the farm.

    No Quota removed

    The code is pretty straight-forward; find the Drop-down list and then remove the "No Quota" option.

    Code for the Delegate control:

       1: protected override void OnPreRender(EventArgs e) {
       2:     Control c = this.Parent;
       3:     if (c != null) {
       4:         c = c.Parent;
       5:         if (c != null) {
       6:             c = c.Controls[23];
       7:             if (c != null) {
       8:                 c = c.Controls[4];
       9:                 if (c != null) {
      10:                     DropDownList ddl = c.Controls[1] as DropDownList;
      11:                     if (ddl != null) {
      12:                         if (ddl.Items[0].Text == "No Quota") {
      13:                             ddl.Items.RemoveAt(0);
      14:                         }
      15:                     }
      16:                 }
      17:             }
      18:         }
      19:     }
      20: }

    Code to add the Delegate control:

       1: <?xml version="1.0" encoding="utf-8" ?>
       2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
       3:   <Control Id="CreateSiteCollectionPanel1"
       4:          Sequence="1"
       5:          ControlAssembly="NoQuotaLockDown, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d4d7ec0041af2eda"
       6:          ControlClass="NoQuotaLockDown.NoQuotaLockDownDelCtrl"/>
       7:  
       8: </Elements>

    Download it!

    You can download the full solution package here NoQuotaLockDown.wsp or the source. NoQuotaLockDownSrc.zip.

    WSS vs MOSS

    This solution works perfect on a Windows SharePoint Services 3.0 farm, but should not be used as-is on a Microsoft Office SharePoint Server 2007 farm. MOSS already uses this delegate control in the SharePoint Portal Server Master Site Directory Capture Control feature. This feature uses sequence 100, so you can easily create a derivative of the MOSS feature and implement the No Quota removal. Another option is to change the delegate control behavior of the create site collection page and allow the delegate control to allow more than one delegate control.

  • Developers, prepare for the 64-bit revolution

    Tags: SharePoint, SQL Server, Virtual Server, Hardware, Windows 7, SharePoint 2010, Windows Server 2008, VMWare, Virtual PC

    The day has come when Microsoft officially started to talk about the next version of Office 2010 clients and SharePoint Server 2010 (no longer Office SharePoint Server). We have since some time known that SharePoint 2010 will be supported only on a 64-bit platform, just as Exchange 2007.

    The new stuff revealed yesterday (as preliminary) are that not only is 64-bit required, it will only be supported on the Windows Server 2008 64-bit platform (including R2) and it will require that you have SQL Server 2008 on a 64-bit platform. There are some other interesting facts that you should check out also in the post (and on about 1.000 other blog posts), but this post is not just about these news.

    The interesting parts of this announcement is that now is the time to learn the 64-bit platform for real and especially Windows Server 2008 R2 and SQL Server 2008, not everything is the same; registry hives, file system, settings, know when to use int (Int32) or Int64 etc etc. You can start now, it's no time to wait! Make a decision to only install your new SharePoint installations on the required SharePoint 2010 hardware, make sure that you have that in your development environments and on your virtual machines. Yes, it will in many cases cost you a bit in new hardware.

    I think that this is the time when 64-bit really will kill the 32-bit era.

    As a bonus I can tell you one thing that I didn't know was achievable. My main laptop runs 32-bit Windows 7 and not 64-bit due to that it does not have the 64-bit driver support for the peripherals and I usually use(d) Virtual PC to virtualize my development servers. Downside with Virtual PC is that you guest machines can only be 32-bit and I don't want to have a Hyper-V laptop in 64-bit mode so I thought that I had to get me a new laptop (which is due for later). I was preparing for the worst of having a dual boot. Fortunately I did a test using VMWare Workstation today and found out that as long as you have a 64-bit capable hardware (which I have) you can host 64-bit guests on a 32-bit host OS. Did you know that, I did not! So I will spend this evening preparing my new development VM's. If you are in the same situation as me, stuck with a 32-bit OS for some time, head on over to VMWare and run the 64-bit compatibility checker and then dump Virtual PC and get VMWare Workstation.

    Welcome to the 64-bit world!

  • ChartPart 2.0 for SharePoint video demonstration

    Tags: SharePoint, CodePlex

    I just had to try out Community Clips from Microsoft Office Labs and made a short video demonstrating the new version of ChartPart 2.0 for SharePoint . The video shows rendering and customization of the graph, how you connect the graph to a list and some of the 3D features.

    Community Clips is an awesome and simple video capture utility that from now on definitely will be a preferred tool in my toolbox.

    Enjoy...and if you like go ahead and download ChartPart 2.0 at http://chartpart.codeplex.com (currently in beta).

    Updated 2009-05-11: clarified that this is ChartPart 2.0 for SharePoint (Services) 3.0

  • Reinstalling SharePoint after a failed Language Pack install

    Tags: SharePoint

    After doing some experimental stuff (don't ask me what!) with my local (Windows 7) SharePoint installation I uninstalled it completely and was going to install it from scratch once again I encountered a strange error. A dialog as below popped up:

    The product ID specified was not found on the machine.

    First I thought that SharePoint did not uninstall correctly and searched the registry as a maniac and found nothing. Then I checked the installation log files, which did not make things much clearer:

       1: Error: Server products do not support select UI Type: InvalidProductFromARP. 
       2: Showing parent-less message Title: 'Setup Error', Message: 'The product ID specified was not found on the machine.' 
       3: Message returned: 1 
       4: Error: Server products do not support select UI Type: InvalidProductFromARP. 
       5: Catalyst execution finished: 05/08/2009 14:52:39.  Return code: 30040.  Exception caught: InvalidProductFromARP. 
       6: PERF: TickCount=11319697 Name=RunSetup Description=End function

    After some investigation I checked the folder that the setup program extracts the files to, which always have the same name and is not removed after the installation is done (*see more information below). It's located in c:\Users\Profile\AppData\Local\xtracted\. There I found some "leftovers" from the failed language pack, see image below. Folders such as WSS.sv-se and WSSLPK.sv-se is used during the installation and therefore checked when installing WSS. And since I have removed everything and have no WSS on the machine it fails when installing the language packs.

    xtracted

    After removing the xtracted folder everything went smooth.

    This little adventure gave a good insight on how the SharePoint installer works and it's a smart one.

    * Worth to notice that all of this is experienced on Windows 7 RC using WSSOnVista. So it might not be the same on a server installation, but I will for sure make sure that the extracted folder are removed before I reinstall SharePoint on any machines in the future. On Windows Server 2003 and Windows Server 2008 I have not seen any leftovers from the xtracted folder, but I have not verified it.

  • Tip: Store your Codeplex passwords

    Tags: Visual Studio, Windows Vista, Windows 7, CodePlex

    Here is a tip for you Codeplex users out there.

    TFS Connect dialog If you are using the Visual Studio and the Team Foundation source control then you are prompted for username and password every time you open up a project. This dialog does not contain any functionality to store the username and password. If you are often opening projects and/or switching projects entering usernames and passwords can get annoying.

    If you are using Windows Vista or Windows 7 you can store the usernames and passwords in a pretty secured way using the Credentials Manager.

    The Credentials Manager is found in the Control Panel, just search for it. To add a username and password all you have to do is click on Add a Windows credential and then enter the name of the Codeplex TFS server (tfsXX.codeplex.com) and then you username and password. Click Ok and then fire up your Codeplex solution in Visual Studio and you are ready to get back to coding!

    Credentials Manager

    Until next time...

  • Say hello to SharePoint STSAdm preupgradecheck command

    Tags: SharePoint

    The Office 2007 Service Pack 2 are here and for the server products (WSS 3.0 and MOSS 2007) we have a new STSAdm command called; preupgradecheck. This command allows you to check any WSS 3.0 SP2 based installation for potential issues that may prevent an upgrade to Windows SharePoint Services 4 (WSS 4.0) or SharePoint Server 2010. For full reference of the command check out KB960577.

    The pre-upgrade check command uses a set of rules found in the 12\CONFIG\PreUpgradeCheck\WssPreUpgradeCheck.xml file to check your farm or you can use a custom file.

    This is how it looks like on a WSS 3.0 SP2 machine when run:

    preupgradecheck

    You will see a summary of all steps while it checks your installation for a few minutes, and when done you can open the HTML log file to dig deeper into your potential problems. There are three categories:

    • Passed (in green) - This is when everything looks fine
    • Information Only (in yellow) - You have to check the log file for more information. The log file may have references to KB articles that you have to read to fully understand what to do to make the upgrade smooth. All manual upgrades are noted here, such as customized fields, CAML views (which are replaced with the new XSLT-based views), custom site definitions (will require a special Upgrade Definition file) etc etc
    • Failed (in red) - This is when there are something that really prevents you from upgrading, read the log file to get the exact reason.

    The sample image above contains two failed steps; one is about referenced features that are missing, which needs to be installed to perform an update. The second one is about the OS prerequisites, this sample is taken from a 32-bit Windows 7 which obviously is not a correct machine since only Windows Server 2008 x64 is supported on the next version of SharePoint.

    It’s well worth running this command on all your installations even though you don’t plan any upgrade right now. The articles contains a great deal of information on how you can make sure that you finally can upgrade your installation smoothly. All articles does not seem to be available yet though…

  • Announcing Windows Live ID Authentication for SharePoint

    Tags: SharePoint, LiveID, CodePlex

    I’m glad to announce that from now on you can find my project Windows Live ID Authentication for SharePoint on CodePlex.

    Windows Live ID Authentication for SharePoint is a project that has been developed for some time for the upcoming Swedish SharePoint Community Site, which will be an awesome site with some really cool features of which this is one.

    I have previously tried some of the available Windows Live ID providers for SharePoint that are out there on the market and the best (previously) one is the provider from the Community Kit for SharePoint, originally developed by Keith Bunge. It has a great basic application design, but had some things that annoyed me and some things I wanted to change, therefore I created my own version, with the CKS version in mind, which I hope that you find useful.

    There are a lot of features in the provider and I have some even greater plans…

    • All configuration done through the SharePoint web interface; Central Administration or in the sites
    • Forces users to register once registered
    • Profile information that is more community-like
    • Profile images
    • Web Parts for displaying last logged in, last registered and all users.
    • Users can be locked
    • Approval of users can be turned on
    • Profile changes can be published to announcement lists
    • Four predefined roles for permissions management

    You can download it now from http://spwla.codeplex.com/, you will also find a document with installation and configuration instructions. There are a few known bugs on which I work on, but if you can spot them or others, please report an Issue on the CodePlex and if you have any suggestions I really like to hear them.

    In upcoming posts I will dig into some of the features a little bit more, but until then here are some screenshots.

    Configuration in Central Administration Logged in users menu Configuration of the Live ID enabled Web Application
    Configuration in Central Administration Logged in users menu Configuration of the Live ID enabled Web Application
    Last logged in members web part Edit personal profile Built-in Live roles
    Last logged in members web part Edit personal profile Built-in Live roles

  • SharePoint Virtualization Survey - preliminary results

    Tags: SharePoint, Virtual Server

    A few days ago I posted a small survey that asks a couple of questions on how you virtualize your SharePoint environments. I will keep the survey open for a couple of more days to get some more results (compared to the number of readers of this blog and number of Twitter followers - the response is really bad…)

    Click Here to take survey

    Anyways I thought that I should put up some preliminary results.

    What virtualization technologies do you use if you virtualize your SharePoint installations

    Microsoft Hyper-V and VMWare ESX Server are the most popular virtualization technologies to use. Microsoft Virtual-PC is also very popular, but probably not in production environments :-)

    2. What virtualization technologies do you use if you virtualize your SharePoint installations

    What environments are you virtualizing?

    Development is the most popular environment to virtualize, not that unexpected. 51,5% virtualizes their production environment.

    What environments are you virtualizing?

    What roles are virtualized?

    Almost everyone virtualizes their web front ends and also recommends them for virtualization. The database role is virtualized by 37,5% and 72,5% does not recommend virtualizing the database role. 50% of the responses does not recommend virtualizing the Index role.

    What roles are virtualized?

    Why virtualizing?

    Why are we virtualizing SharePoint? Almost everyone agrees on that the hardware costs are lower, but the license cost is the same or even higher. Very few users agrees on that the performance is better, but instead the scalability and redundancy is improved.

    That development is easier with virtualization is no doubt about (we don’t even need a survey for this…).

    I’m also glad that at least 2/3 of the responses agrees on that this is good for the environment.

    This was a short preliminary result of the survey, I will run it for a few more weeks, so please pass the survey forward to your friends and colleagues.

    Click Here to take survey

  • SharePoint Virtualization Survey

    Tags: SharePoint, Virtual Server

    Virtualization is a really hot technology right now, and forward and so are SharePoint. I’ve been discussing SharePoint virtualization internally and externally for sometime now and I have my opinions. In order to get a broader view on how SharePoint is virtualized around the globe I put together a small survey that will enlighten this subject.

    I would like you to fill out the survey and forward it to your colleagues, partners, clients, friends and better halves.

    Click Here to take survey

    I will once I get enough answers post them here in full and as well do my analysis of them.

  • Update to the Custom code with SharePoint Online and Windows Azure, due to bug in SharePoint Online

    Tags: SharePoint

    A few weeks back I wrote a post on how to mix Windows Azure and SharePoint Online called Custom code with SharePoint Online and Windows Azure. Since then both Windows Azure and SharePoint online have had some updates.

    First of all you no longer need to create the bindings in the code to make it fully trusted. Good to know but it does not affect the solution.

    A Bug in SharePoint Online Web Services

    More important is the fact that you cannot longer use the Visual Studio Add Service Reference function and add the services from your SharePoint Online site to your solution. You will end up with an error like this:

    Add Service Reference Error

    It says that it cannot recognize the document format of the Lists.asmx?WSDL and Lists.asmx?disco documents. Why?

    If you open up the Lists web service in a browser you get the standard auto generated ASMX page:

    Lists.asmx

    From this page you can check out all the web service operations, but when you click on the Service Description link, which would take you to the /_vti_bin/Lists.asmx?WSDL page, which contains the definitions of the web service and it’s operations you get an error. The same errors that Visual Studio gets.

    Lists.asmx?WSDL Fail!

    This page should contain XML and look like this (taken from a normal WSS 3.0 installation):

    Lists.asmx?WSDL working!

    So what is happening in SharePoint Online!? If you take a look at the source of the faulty WSDL page you will see an error message saying something like this:

    The requested page does not contain a link to the Microsoft Online Services Privacy Statement. The page cannot be displayed until a link to the Privacy Statement is added. Please notify your SharePoint site administrator. Only the site administrator or site owner can add the Privacy Statement. For information on adding the statement, see: Add the Privacy Statement to your SharePoint Online Site.

    This error message is shown on all ASPX pages in SharePoint Online that does not contain a link to the Microsoft Online Services Privacy Statement, which is a requirement in SharePoint Online. The link in the error message tells you how to include this message in your custom ASPX pages.

    But, we just looked at a ASMX page, I can’t have statements like this in my web services!?

    Let’s dig a little bit deeper into the SharePoint 12-folder. In the ISAPI folder you have the Lists.asmx file, as well as a Listsdisco.aspx and a Listswsdl.aspx file. Normally in ASP.NET when you create your own ASMX file the WSDL and DISCO will be created automatically but SharePoint silently uses these other two files, instead of creating them at runtime. Because these two files are ASPX files you need to have that Privacy Statement.

    This is in my opinion a real bug in SharePoint Online, and should be corrected as soon as possible.

    How to work around the bug?

    It’s pretty easy to work around this bug. All you have to do is when adding the service reference is to get the web service from a normal SharePoint installation (WSS or MOSS) and then in your service binding point to your SharePoint Online address.

    I hope that the Microsoft Online team come up with a solution to this problem as soon as possible, since it will cause headache for a lot of developers.

  • 5 files you should know in the SharePoint 12-hive

    Tags: SharePoint

    The SharePoint 12-hive contains by default a number of interesting files that every developer should be aware of. The more you know the better you understand the inside of SharePoint and it allows you to create more efficient and better solutions.

    Here are my top five favorite files:

    ctypeswss.xml (in TEMPLATE\FEATURES\ctypes)

    This is the feature elements file for all the default WSS Content Types. When creating new content types, most often I find it useful to derive them from existing content types. For example if I need to create a content type that derives from the standard content type Task, i can easily get the content type ID, which is used when creating new content type IDs, and what Site Columns that content type has.

    fieldwss.xml (in TEMPLATE\FEATURES\fields)

    Second favorite is the elements file for the WSS Site Columns feature. In this file all definitions for the default WSS Site Columns is found. Together with ctypeswss.xml this is really handy when creating custom content types. By finding out the ID’s of the Site Columns you can easily re-use the site columns when creating content types.

    Custom List schema.xml in (TEMPLATE\FEATURES\CustomList\CustList)

    Whenever I need to create a list definition and need to create a schema.xml I use the schema.xml for the Custom List feature and copy it to my definition.

    STS onet.xml in (TEMPLATE\SiteTemplates\STS\Xml)

    This is the file to check out when creating Site Definitions. The onet.xml file contains all Site Definitions (althought the folder is called SiteTemplates), which includes navigation, lists etc. Most often I copy this file (and all other files in the STS folder) and remove almost everything except the the blank site def.

    DOCICON.xml (in TEMPLATE\XML)

    Perhaps not that interesting that the four above, but on nearly all installations you update this file with the PDF icon (at least). What this file does it that it allows you to map an extension (or ProgID) to an icon and optionally specify an editor.

    What’s your favorite ones?

  • SharePoint Designer is now free

    Tags: Microsoft Expression, SharePoint

    SharePoint Designer is now a free tool and available for download.

    What does this mean really?

    Anybody can download it and customize their SharePoint installations which is good in some ways, but really bad in others. If the users are not aware of what they are doing they can cause severe damage to your SharePoint, but it can also make really nice enhancements to their installation.

    There are a lot of nice things you can do with SPD in your sites that you can’t do using the web interface. The web interface on the other side protects you pretty good from doing some mistakes that even the best can do once in a while, like dragging a file or folder to the wrong place. Of course all of this has been possible to do before with SPD, it’s not a new product, but suddenly you can expect a number of new and untrained end-users fire up the SharePoint Designer and customizing in ways you never prepared your installations for.

    What should you do?

    First of all make sure that you have the permissions correctly set up in your SharePoint environment and make sure that you have good (and working) backup and restore plans.

    Secondly restrict the usage of SharePoint Designer by locking it down. Read this article from the SPD team on how to do it.

    Then you should of course train them in SharePoint Designer and explain the pros and cons. Microsoft has a step-by-step training guide that can be downloaded.

    What if I already purchased it?

    If you have purchased SharePoint Designer 2007 and have Software Assurance coverage then you are eligible for Expression Web 2. Isn’t that sweet! Here are some more reading on the new SharePoint licensing.

    System requirements!?

    If you take a look at the System Requirements for SharePoint Designer, you see that it only supports Windows Server 2003 and Windows XP!?

    SharePoint Designer System Requirements

    Mistake or not, I don’t know? If anyone does please comment below. But I’ve “never” had any problems with it on Windows Vista or Windows 7.

  • How to make Live Mesh conquer the world...

    Tags: Microsoft, Microsoft Office, Internet and the Web, Windows Live, Live Mesh

    Today almost everyone have more than one computer; one at work, a few at home, a media center, a PC, a Mac etc, your family members, friends and colleagues have the same. One problem is that a lot of us need access to files on one machine when we are using one of the others. For example I want to access my images when I’m at work sometimes and I do not want to copy all of these images onto my work laptop, when I’m at home I want to have the same favorites and documents that I use at work and so on. Then I have another scenario, let’s say that I do not have any of my computers with me and I want to access one of my files, then I want to have some way to access the files using a standard browser - and why not have editing possibilities.

    There are several ways to accomplish this, but none (that I discovered) covers all of these scenarios. Today I use a mix of services from Microsoft (there are other vendors with similar services, but none as good IMHO); Live Mesh, Office Live Workspaces, Live Skydrive and Live Sync. Read my previous post which compares some of these features.

    Live Mesh synchronizes folders between my machines as well as keeps a copy of it in the cloud. Live Sync synchronizes between the machines only. Office Live Workspaces allows me to store, share and access Office documents, lists and calendars in the cloud. Skydrive is currently a backup repository in the cloud. This pretty much covers it all, but has a few problems:

    1. I need to have several applications/services installed
    2. I need to go to different web sites to configure or access files
    3. They all use different storage mechanisms
    4. The synchronization (Mesh, Live Sync) always make a bi-directional synchronization

    Why not take these services and make one über-Mesh and add some additional features. Take the Live Mesh application and add this features then you would have a synchronization service that would take the world with storm.

    Modify Live Mesh in the following ways

    1. Merge the Skydrive storage with the Mesh storage - then we will go from 5Gb to 25Gb online storage
    2. Allow the Mesh folders to synchronize only between the computers and not the cloud, like Live Sync. I do not need all my files available in the cloud. For example I use Mesh to have some applications synched across my machines, just like Andrew Connell does.
    3. Allow you to set how the files will be synchronized; one-way or bi-directional. For example I only want my images taken with my mobile phone to be copied to the mesh, not to synchronize all images with the phone. This should be a setting per device and folder
    4. Today in Live Mesh you can only add top-folders, it would be awesome if you could make your own folder structure and set the synchronization options per folder
    5. Integrate the Office Live Workspaces folders into the Live Mesh
    6. Integrate the upcoming Office Live Applications into the Live Mesh, the opportunity to edit my Office documents using a browser only would really rock
    7. Have a REST based API to the Live Mesh - then all vendors could Meshify their applications
    8. Make the Live Mesh WebDAV compliant, then I could use any Office application from anywhere and edit my documents directly in the Mesh, without having to synchronize the folders
    9. Keep the Live Mesh RDP access
    10. Keep the Live Sync remote folder access
    11. Keep the Live Sync file size limit, Skydrive does not allow upload of large files

    Anything else you would like to have?

    Of course I realize, and don’t mind, that some of these services should have some fee; for example the Office Live Applications integration could have some fee and extra storage space (25Gb is not that much in these days) should also cost.

    I’ve even tried the Live Mesh CTP version, which have support for custom applications - which looks awesome, throw that into the wish-list also.

    So, Microsoft Program Managers hear me! Now when Ray Ozzie is in partial command in Redmond I think this should have a high priority (anyone remember Groove?)

    I do not think I am the only one out here that would just love to see this happen.

  • Having fun with the SharePoint Welcome.ascx control

    Tags: SharePoint

    SharePoint Welcome Control Have you ever wanted to get rid of the Welcome text before the user name in the SharePoint user menu? At least I have! If you are like me - here is a solution that you can use to customize the text of the Welcome Control (Welcome.ascx).

    The approach is pretty simple, and can be made in several ways, but I wanted a pretty clean solution that didn’t affect any other behavior of SharePoint and I wanted to write as little code as possible. Eventually I ended up with some more rows than expected, but this was due to the fact that I created this custom Welcome control configurable and deployable.

    First of all some basics about the Welcome control. The Welcome.ascx control is a special control that handles the user menu, located top right (as standard) in your SharePoint site. The control has two states; one if the user is signed in and one when the user is not signed in. The Welcome.ascx control is located in the 12-folder under TEMPLATE\CONTROLTEMPLATES and uses the Microsoft.SharePoint.WebControls.Welcome control class in the Microsoft.SharePoint DLL file.

    What I wanted to do was get rid of the Welcome text in front of the user name and only have the user’s name. To achieve this without recreating the whole control, I created a new class which derives from the Welcome control and changed the Welcome.ascx file to inherit from my new class instead.

      1: namespace ManagedWelcome {
    
      2:     public class Welcome : Microsoft.SharePoint.WebControls.Welcome {
    
      3:         protected Welcome() {
    
      4:         }
    
      5: 
    
      6:         [SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
    
      7:         protected override void OnLoad(EventArgs e) {
    
      8:             base.OnLoad(e);
    
      9: 
    
     10:             if (HttpContext.Current.User.Identity.IsAuthenticated) {
    
     11:                 PostCacheSubstitutionText pt = base.ExplicitLogout.MenuControl.Controls[0] 
    
     12:                                                as PostCacheSubstitutionText;
    
     13:                 pt.TextType = PostCacheSubstitutionTextType.UserName;
    
     14:             }
    
     15:         }
    
     16:     }
    
     17: }

    The original Welcome control consists of two objects; ExplicitLogout (of the type PersonalActions) and ExplicitLogin (of the type ApplicationPageLink). In line 13 I change the TextType property (enumeration of type PostCacheSubstitutionTextType) of the first control (which is of the type PostCacheSubstitutionText) in the ExplicitLogout object and set it to show only the user name (UserName enum value), default is the WelcomeUser value.

    Now the Welcome control looks like this instead.

    No Welcome text!

    As always I cannot stop there so I made this into a customizable control, download below, which can be deployed to your web application. When activated, on Site Collection Features, it adds a link to the Site Collection Administration (not the best place, since the changes will affect the whole web application).

    Site Collection Administration

    When you click that link you will get to a Welcome Control administration page, where you can set the behavior of the Welcome control when a user is logged on or change the Sign In text.

    Welcome Control admin

    Using this feature you can on the fly change the behavior of the Welcome menu; have a custom Sign In text, change the welcome text to just the user name, the user login name, or e-mail and even the name of the Web.

    Note: When installing this feature it will write over the default Welcome.ascx control, so make a backup of it first.

    For full source download click here or just the solution package (WSP) click here.

  • Ten free sample Themes for SharePoint

    Tags: SharePoint

    Microsoft has released a set of ten free Themes for SharePoint for use with the Visual Studio extensions for Windows SharePoint Services.

    10 Themes Preview

    These ten themes provides a far better experience than the out-of-the-box themes delivered with SharePoint (WSS and MOSS), of which some are really annoyingly ugly!  But the new themes needs some tweaking before looking really good, there are several design flaws in some of them, like black text on dark-grey background…

    The themes are not delivered as SharePoint solutions, but as Visual Studio 2008 solutions for usage with the VSeWSS. So you can’t just download and install them, you have to build them and optionally customize them. This allows you to easily grab a solution, customize it a bit and then package and deploy it.

    To download the themes go to: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=0a87658f-20b8-4dcc-ad7a-09ad22641f3a

  • ChartPart 2.0 for SharePoint Beta released

    Tags: SharePoint, Web Parts

    ChartPart 2.0 betaI’m glad to announce that I finally got my stuff together and stitched together the last pieces of the beta of ChartPart for SharePoint 2.0.  ChartPart for SharePoint is a SharePoint Web Part that allows you to draw charts from existing SharePoint lists. It’s available at CodePlex, at http://chartpart.codeplex.com/, and is free for use.

    ChartPart 1.0 have had over 4.000 downloads since it was released and is translated to six different languages. The first version was pretty limited in customization and you could only create some basic charts.

    Version 2.0 has a number of new and interesting features

    • Installation in bin, instead GAC. This is to make the Web Part more reliable by enterprise customers
    • The Chart Controls is installed separately
    • More chart types
    • A set of new and improved Editor Parts that allows you to customize your Chart
      • Full control over the 3D graphs
      • Full control of legends position and layout
      • etc
    • A new LockDown mode, which allows you to lock down the design parts of the ChartPart so that an administrator can set colors and design and the allow users to use those predefined Web Parts without violating corporate branding etc
    • Connect the ChartPart to a list and use the list as a filter for the chart
    • Even more languages will be there when a stable version is released

    It’s a beta, and I have some issues still to fix and some features to implement, but head on over to download it if you would like to try it out, head on over to CodePlex and download the beta. Post any issues in the Discussions or Issue Tracker. If you would like to help out translating it just contact me.

  • SharePoint Web Part Event Flow in detail

    Tags: .NET, SharePoint, Web Parts

    I have been answering questions on the SharePoint forums at MSDN Forums, and while some are really tricky and interesting, some are really basic beginner mistakes. A couple of questions lately have been about Web Part development and how to and where to create your controls. Most of these is easily solved if you understand how the Web Part event model works.

    First of all you need basic ASP.NET understanding and know how the Page and Control objects work together, how a postback works etc. But I have even seen somewhat experienced ASP.NET developers failing at this point, probably due to the fact that Visual Studio have a slick interface for editing user controls and ASP.NET pages. When it comes to SharePoint you have no visual aids and you are out on thin water, and this knowledge is crucial.

    SharePoint Web Part - Event Flow chart

    To help new (or experienced) SharePoint Web Part developers out I created a chart that shows you how the different events flows from the Page, through the WebPartManager and WebPartZones, to the Web Part.

    WebPartEventModelChart

    You can either click on the image above, to get it as a JPEG image, or download it as a printable PDF or XPS file.

    Note: The Event Flow chart does not cover all events in the ASP.NET/SharePoint Page model, I have focused on the WebPart side.

    There are five segments in the chart, from left to right;

    • Page - events/methods happening in the Page (System.Web.UI.Page derivatives)
    • WebPartManager - events/methods in the SPWebPartManager (inherited from WebPartManager)
    • WebPartZone - the WebPartZone does not do really much in this scenario but rendering the WebParts.
    • WebPart - the events happening during a normal view of a WebPart
    • WebPart Postback - the event flow is a little bit different than the normal WebPart flow. Note that CreateChildControls is before the OnLoad and connections.

    The chart contains a few white notations; these are not actual events/methods but contains information on what is happening at that point.

    If you have any suggestions or comments about the flow, please feel free to contact me or post a comment. I’ll gladly keep the chart up to date.

  • Why you should not allow users to Close Web Parts

    Tags: SharePoint, Web Parts

    A Web Part, in SharePoint or not, has a Verb that allows the Web Part to be Closed. Closed means that the Web Part is just closed (not rendered) and not deleted, which is a separate Web Part Verb. Closing Web Parts can cause headache for your users and even a really bad performance.

    Note: To delete a Web Part you have to go in to Edit mode for the page. Close can be done directly from the Web Part menu.

    Headache for your users

    Advanced Web Part gallery and options When you close a web part it is visually removed from the page and can only be retrieved back by appending ?Contents=1 to your web part page URL or by editing the page, click Add a Web Part, click Advanced Web Part gallery and options and then select Closed Web Parts. None of these options are intuitive and my guess is that not many administrators or users are aware of this.

    Most probably your users will end up creating and configuring a new Web Part, which eventually will be closed also, and so on.

    This will make your Web Part storage grow and after a while your page will start to perform bad. It can get even worse when you allow the users to customize their own pages.

    Bad performance

    Why does the page perform so badly when you have a lot of closed Web Parts? The answer is twofold; first of all it takes storage and resources to handle these closed web parts and secondly the closed Web Parts are actually created on every page load! They are not rendered but the Web Part Manager control creates all Web Parts (closed or not) during the pre render phase and checks if any of the Web Parts has any client scripts that needs to be registered with the Web Part Page Services (WPSC) framework.

    Note: if you are creating your own Web Parts, based on the SharePoint WebPart class, and you do not need to register any client scripts then override the RequiresWebClientScript and return false.

    Nothing else is done with the closed Web Parts, but if you (god forbid) have any initializations in the constructor you can make the situation even worse.

    Resolution

    Fortunately this problem can be solved in a very easy way; you can prohibit a Web Part from being closed by using the built-in Web Part property AllowClose and set it to false (default is true). You can do this in three different ways;

    1. Allow Close You can change the value of the Allow Close property by editing the Web Part and under Advanced you will find an Allow Close check box
    2. If you develop the Web Part yourself then you can override the property in your class
    3. You can modify the .webpart or .dwp file and set the value of the AllowClose property

  • 70-631 passed

    Tags: SharePoint

    After passing the developer exams of WSS (70-541) and MOSS (70-542) I thought that I should make the deck complete by taking the configuration exams. Today I passed the first one, Windows SharePoint Services 3.0 - Configuration (70-631). I’m mainly a developer so I had some worries about questions on DNS, network configs and load balancing. But this exam was too easy and kept at a very basic level. I missed one question though. All of these exams follow the same pattern - I whish the creators of them had some more imagination and creativity.

    The exam felt a bit out of date since it had some questions referring to MOM 2005 and the HTML viewer (which has been missing from MS downloads for some time, if anybody has any statement on this please comment).

    So now it’s just one more to take, before the SharePoint 3.0 life cycle comes to an end, then we have to start over…

  • Office Labs - Canvas for OneNote

    Tags: Microsoft Office

    Canvas for OneNote is another new and interesting innovation from the Office Labs team. Canvas for OneNote creates a new way for you to manage your OneNote section and pages in a more “inspirational” and “irregular” way.

    OneNote is traditionally organized into Note books, sections, groups, pages and subpages - just like a classical book shelf filled with note books. It works really nice if you know in which note book you placed your notes (of course you can search to find it…faster than you search your shelf). This feels a little bit old-school to me and I still have a lot of hand notes and documents spread out over my desktop (not the Windows desktop, a real physical one) organized in a very strict chaotic order.

    Canvas for OneNote is one step forward to keep your notes in a more irregular order and to view them in a more visual way. You can see all your notes/pages just as you would put them on a desktop and drag them around and organize them into groups to cluster related sections and pages together. By zooming in and out you can really fast find and edit the notes. One interesting feature is to use the time line mode, which highlight the pages changed within a specified time period.

    Canvas for OneNote

    Canvas for OneNote is right now an experimental project and has some show stoppers, for me who is an OneNote addict. You can only import (makes a copy of) one OneNote section (I use several ones), it drains the battery of your computer (normally draw notes on meetings without power supply) and I think that a search function should be there. But the team are right on track - I really would like to see something like this in upcoming versions of OneNote (read OneNote 14).

    This type of interfaces is something we need to see more of, don’t you agree. And I really would like to see it in other applications/systems. Just look at this interface from Bumptop - imagine that on a Tablet PC.

  • SharePoint Online available worldwide

    Tags: SharePoint

    At CeBIT 2009 it today was announced that SharePoint Online is now available worldwide*. SharePoint online is a part of the Business Productivity Online Suite which also contains Exchange Online and Live Meeting. More services will be available at a later date.

    There is a free 30 days trial option if you would like to try it out, which I really recommend, before you subscribe/buy the solution.

    You can find more information about the Microsoft Online Services at http://www.microsoft.com/online.

    * These are the possible countries: Austria, Belgium, Canada, Denmark, Finland, France, Germany, Ireland, Italy, Japan, Netherlands, New Zealand, Norway, Portugal, Spain, Sweden, Switzerland, the United Kingdom and the United States

  • SharePoint 14 delayed until 2010

    Tags: SharePoint, Microsoft Office

    Not that unexpected, but Microsoft chief executive office Steve Ballmer has confirmed that the new Office 14 clients and servers (read SharePoint) will not be released during 2009. The products will be “generally available” during 2010.

    Generally available may indicate (I’m always positive) that we have a release for volume licensees and partners in late 2009 and in the shelves during 2010 (just like the previous version).

    Read SharePoint Daily Special Edition for more information.

    I’m not surprised since the lid has been on for so long and for such a significant server product such as SharePoint it really needs time for a beta phase. The adoption of WSS 3.0 and MOSS 2007 has really boosted and having a to short period for extensive testing and upgrade preparation would not be appreciated.

    Now we all can wait for the beta period to start, and hope for a universal change in the number of hours per day, I sure need some more…

  • Custom code with SharePoint Online and Windows Azure

    Tags: .NET, C#, SharePoint, Visual Studio, Microsoft Office, Office Open XML, Windows Azure

    When I first heard about SharePoint Online at the PDC 2008 I was a bit disappointed that you could not use custom code but had to rely on the built-in functionality and the things you could do with SharePoint Designer (which is quite powerful anyway, especially with jQuery).

    To read more about SharePoint online, head over to Tobias Zimmergrens blog.

    But with some clever techniques you can take advantage of the Windows Azure Hosted Services and create your custom code. I will show you how to create some custom code, which normally is done by SharePoint event receivers or timer jobs, using a Worker Role in Windows Azure.

    The post is quite lengthy but I have skipped some of the code snippets to make it easier to read. You will find downloads of the C# code at the end of this post.

    Scenario

    This sample assumes that we have a Document Library in SharePoint Online containing Word 2007 documents for Proposals. The library is called Proposals. We want to make sure that our Proposals has all comments removed before we send it away to our clients. This comment removal procedure will be initiated by a workflow.

    The Document Library

    Action column The Proposals Document Library is a standard SharePoint Document Library with versioning enabled. First we add a new column to the library called Action. This column will contain the status of the comment removal procedure. It has the type Choice and three possible values; RemoveComments, Processing and Done.

    The workflow

    Using SharePoint Designer we create a new workflow, called Prepare Proposal. The workflow has three stages. The workflow is initiated manually

    1. SPD Workflow designerSet the Action column to the RemoveComments value
    2. Wait for Action column to get the value Done
    3. Send e-mail the the author

    Pretty simple workflow but all using the out-of-the-box SharePoint Designer activities.

    So far everything is basic SharePoint Online “development”, but now we head on over to the custom coding parts.

    Create the Hosted Service Worker Role

    Using Visual Studio 2008 and the Windows Azure SDK we can create a new project of the type Worker Cloud Service. This cloud service will contain all our code for removing the comments from our Word documents.

    Cloud Service templates

    When the project is created, actually a solution with two projects, we add two references to our Worker Role project; WindowsBase.dll and DocumentFormat.OpenXml.dll (from Open XML SDK 1.0). The Open XML reference must also have the Copy Local property set to true, so that the assembly is deployed with the hosted service App Package.

    Note: Version 2 of Open XML SDK can not be used since it does not have the AllowPartiallyTrustedCallers attribute, which is required for all referenced assemblies in Windows Azure.

    Add a service reference

    The worker role will use the SharePoint Online web services to read and update data so we need to add a Service Reference to our SharePoint online site and the Lists.asmx web service. When this is done an App.config file is created, just delete it - we have to set our bindings and endpoints in the code so it is fully trusted.

    In your worker role Start method you create code as follows:

      1: BasicHttpBinding binding = new BasicHttpBinding();
    
      2: binding.Security.Mode = BasicHttpSecurityMode.Transport;
    
      3: binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    
      4: binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
    
      5: binding.Security.Transport.Realm = WorkerRole.Realm;
    
      6: binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

    WorkerRole.Realm contains a string with your SharePoint Online Realm with a value something like this: “XXXXXmicrosoftonlinecom-1.sharepoint.microsoftonline.com”.

    Let’s code!

    The worker role will poll the Proposals library for new documents which has the RemoveComments value in the Action column. This is done with the GetListItems method and a query selecting only those documents.

      1: XElement query = new XElement("Query",
    
      2:     new XElement("Where",
    
      3:         new XElement("Eq",
    
      4:             new XElement("FieldRef",
    
      5:                 new XAttribute("Name", "Action")
    
      6:                 ),
    
      7:             new XElement("Value",
    
      8:                 new XAttribute("Type", "Choice"),
    
      9:                 "RemoveComments"))));
    
     10: 
    
     11: XElement queryOptions = new XElement("queryOptions");
    
     12: 
    
     13: var itemsXml = client.GetListItems("Proposals", string.Empty, query.GetXmlElement(), null, string.Empty, queryOptions.GetXmlElement(), string.Empty);
    
     14: 
    
     15: XNamespace s = "http://schemas.microsoft.com/sharepoint/soap/";
    
     16: XNamespace rs = "urn:schemas-microsoft-com:rowset";
    
     17: XNamespace z = "#RowsetSchema";
    
     18: 
    
     19: var docs = itemsXml.
    
     20:     GetXElement().
    
     21:     Descendants(z + "row").
    
     22:     Select(x => new {
    
     23:         Title = (string)x.Attribute("ows_LinkFilename"),
    
     24:         Id = (string)x.Attribute("ows_ID"),
    
     25:         Url = WorkerRole.Url + "/Proposals/" + (string)x.Attribute("ows_LinkFilename")
    
     26:     });
    
     27: 

    Now we have all our proposals in the docs variable and we can iterate over it.

      1: foreach (var doc in docs) {
    
      2:     RoleManager.WriteToLog("Information", "Processing: " + doc.Title);
    
      3:     setStatusOnDocument(client, doc.Id, "Processing");
    
      4: 
    
      5:     WebRequest request = HttpWebRequest.Create(doc.Url);
    
      6:     request.Credentials = new NetworkCredential(WorkerRole.Username, WorkerRole.Password);
    
      7: 
    
      8:     MemoryStream mems = new MemoryStream();
    
      9: 
    
     10:     using (WebResponse response = request.GetResponse()) {
    
     11:         using (Stream responseStream = response.GetResponseStream()) {
    
     12:             byte[] buffer = new byte[8192];
    
     13:             int offset = 0;
    
     14:             int count;
    
     15:             do {
    
     16:                 count = responseStream.Read(buffer, 0, 8192);
    
     17:                 offset += count;
    
     18:                 mems.Write(buffer, 0, count);
    
     19:             } while (count != 0);
    
     20:             using (WordprocessingDocument wpDoc = WordprocessingDocument.Open(mems, true)) {
    
     21:                 RemoveComments(wpDoc);
    
     22:             }
    
     23:             using (WebClient wc = new WebClient()) {
    
     24:                 wc.Credentials = new NetworkCredential(WorkerRole.Username, WorkerRole.Password);
    
     25:                 wc.UploadData(doc.Url, "PUT", mems.ToArray());
    
     26:             }
    
     27:         }
    
     28:     }
    
     29:     setStatusOnDocument(client, doc.Id, "Done");
    
     30:     RoleManager.WriteToLog("Information", "Comments removed from: " + doc.Title);
    
     31: }
    
     32: 

    First of all we have a method which updates the Action column of the item to Processing to indicate to the users that we are currently processing this document. Then we read the document into a stream and pass it into a WordprocessingDocument object. On that object we do the RemoveComments method which removes all comments in the Word 2007 document.

    Note: Have a look at Eric Whites blog for some nifty operations on your Open Xml documents, such as the remove comments function.

    When all comments are removed we upload the file back to SharePoint and set the status to Done, and we are all set.

    As you can see I use three different techniques to read from the SharePoint Online site; the SharePoint web services, request-response and a simple WebClient. Isn’t coding fun!

    Test

    One of Windows Azures beauties is that you can test it on your local machine using the Azure Development Fabric. Just hit F5 in Visual Studio.

    Development Fabric

    This allows you to debug and fine tune your code and see how it scales out.

    Deploy to Windows Azure Staging environment

    Hosted Service When you are sure that there are no bugs just choose Publish in Visual Studio and it will open up a web browser which directs you to the Azure Services Developer Portal, there you can create a new Hosted Service Project or choose an existing one to use for this Proposals service.

    To deploy this solution we have to upload two files; the  App Package containing all your code and references and the Configuration Settings file, both automatically created by Visual Studio.

    Deploying

    When this is done you have to wait a few minutes so Windows Azure can allocate resources for you and prepare the environment. Once this is done you are ready to test your service in the cloud.

    In staging

    Just hit the Run button and after a minute or so the Proposals Service is running - in the cloud!

    Deploy to Production

    For us used to the SharePoint environment and the mess it is to get from development to staging to production environment it’s so much fun to just hit Deploy in Windows Azure to move the Staging service to Production.

    Production

    As you can see from the image above this solution is now in production and started with one worker role.

    Run the workflow

    Now we can test our complete solution by uploading a document containing some comments. Then initiate the Prepare Proposals Workflow.

    Prepare Proposal

    The document will be updated with a new value in the Action column.

    In Progress

    After a few seconds the document is updated by the cloud worker role we created, the workflow completes, there are no more comments in the document and the author should have received an e-mail with information that the workflow is done.

     Done

    Summary

    This was a short demonstration on what you can do with the standard functionalities of Microsoft's cloud offerings such as SharePoint Online and Windows Azure. The scenario was quite simple but using the same techniques you can elevate your SharePoint Online experience and functionality a lot.

    Using Windows Azure is one possibility to host your online custom code, hosting it on on-premise servers is another option and it works just as fine.

    Note: I have not made this sample so it can scale out nor does it handle any exceptions. Take it what its for.

    If you would like to look at the code you can find it here.

    Happy coding!

  • Web Part Properties - part 6 - Complex Properties

    Tags: .NET, SharePoint, Web Parts

    To end my series of Web Part properties I would like to show how to store more complex values than just strings or integers. What happens if you would like to store a more complex object; an array or a coordinate etc?

    Editing these properties with the standard generated interface using the WebBrowsable and Personalizable attributes will not work, since it only accepts basic types, shown in part 1. To make these properties editable you have to (almost…continue reading) create an EditorPart, shown in part 2, and control the properties in the SyncChanges and ApplyChanges methods.

    Note: For more information on which basic types that can be used in the standard toolbar see the PropertyGridEditorPart documentation on MSDN.

    SharePoint Designer and complex properties

    If you are using SharePoint Designer to edit your Web Parts, you can manage your complex properties a little bit more. For example if you store have string array, it will not be visible in the web interface, but it can be edited in SharePoint Designer.

      1: [WebBrowsable]
    
      2: [Personalizable]
    
      3: public string[] AnArray {
    
      4:     get;
    
      5:     set;
    
      6: }

    The property above will not be seen in the web interface but in SharePoint Designer it will look like this:

    SPD

    If you click on the ellipsis button you will get a dialog in which you can edit the string array.

    Custom objects without EditorParts

    But if you still don’t want to create your own EditorPart you can use some .NET development techniques, familiar to you who have been working a lot with WinForms.

    Let’s say that we want to have a Coordinate property that we would like to use in our web part, the class should look like this:

      1: public class Coordinate {
    
      2:     public float Latiude;
    
      3:     public float Longitude;
    
      4:     public override string ToString() {
    
      5:         return this.Latiude.ToString(CultureInfo.CurrentCulture) + 
    
      6:                ":" + 
    
      7:                this.Longitude.ToString(CultureInfo.CurrentCulture);
    
      8:     }
    
      9: }

    And we expose it through our web part like this:

      1:  [WebBrowsable]
    
      2:  [Personalizable]
    
      3:  public Coordinate Coordinate {
    
      4:     get;
    
      5:     set;
    
      6: }

    This property will not be shown in the web interface and will not be editable in SharePoint Designer. Now to get this to work, editable in the web interface as well as in SPD, we have to create an implementation of the ExpandableObjectConverter class. We will override four methods so we can convert a Coordinate to and from a string representation. The string representation is implemented in the ToString() in the code above. The whole implementation of the class looks like this:

      1: public class CoordinateConverter : ExpandableObjectConverter {
    
      2:     public override bool CanConvertTo(ITypeDescriptorContext context, 
    
      3:                          System.Type destinationType) {
    
      4:         if (destinationType == typeof(Coordinate))
    
      5:             return true;
    
      6:         return base.CanConvertTo(context, destinationType);
    
      7:     }
    
      8:     public override object ConvertTo(ITypeDescriptorContext context, 
    
      9:                            CultureInfo culture, object value, 
    
     10:                            System.Type destinationType) {
    
     11:         if (destinationType == typeof(System.String) && 
    
     12:             value is Coordinate) {
    
     13:             Coordinate coord = (Coordinate)value;
    
     14:             return coord.ToString();
    
     15:         }
    
     16:         return base.ConvertTo(context, culture, value, destinationType);
    
     17:     }
    
     18: 
    
     19:     public override bool CanConvertFrom(ITypeDescriptorContext context, 
    
     20:                          System.Type sourceType) {
    
     21:         if (sourceType == typeof(string))
    
     22:             return true;
    
     23:         return base.CanConvertFrom(context, sourceType);
    
     24:     }
    
     25:     public override object ConvertFrom(ITypeDescriptorContext context, 
    
     26:                            CultureInfo culture, object value) {
    
     27:         if (value is string) {
    
     28:             try {
    
     29:                 string s = (string)value;
    
     30:                 string[] arr = s.Split(':');
    
     31:                 Coordinate coord = new Coordinate();
    
     32:                 coord.Latiude = float.Parse(arr[0], 
    
     33:                                 CultureInfo.CurrentCulture);
    
     34:                 coord.Longitude = float.Parse(arr[1], 
    
     35:                                   CultureInfo.CurrentCulture);
    
     36:                 return coord;
    
     37:             }
    
     38:             catch {
    
     39:                 throw new ArgumentException("Can not convert '" + 
    
     40:                           (string)value + "' to type a Coordinate");
    
     41:             }
    
     42:         }
    
     43:         return base.ConvertFrom(context, culture, value);
    
     44:     }
    
     45: }

    To make SharePoint and SharePoint Designer aware of that we now can convert our Coordinate class to a string representation we have to set the TypeConverter attribute on our Coordinate class. The final Coordinate class should look like this:

      1: [TypeConverter(typeof(CoordinateConverter))]
    
      2: public class Coordinate {
    
      3:     public float Latiude;
    
      4:     public float Longitude;
    
      5:     public override string ToString() {
    
      6:         return this.Latiude.ToString(CultureInfo.CurrentCulture) + 
    
      7:                ":" + 
    
      8:                this.Longitude.ToString(CultureInfo.CurrentCulture);
    
      9:     }
    
     10: }

    If we now modify our web part we will see this in the web interface, sweet huh?

    Coordinate

    If we try to set it to any other value than we allow in our ConvertFrom method above, then we will get a nice error:

    Coordinate error

    The Coordinate property can also be edited in SharePoint Designer:

    Coordinate editing in SPD

    Other methods

    There are other ways to make your web part handle complex properties. Wesley Bakker has a nice write up on how to use JSON notation to store and edit the values.

    That was all folks…

  • Once SharePoint, Always SharePoint - what's wrong with that?

    Tags: SharePoint

    Computer Sweden has an article in today's issue, also published online yesterday, called “Impossible to get rid of the cash cow of Microsoft”. To sum it up briefly it discusses how hard it is to get rid of Microsoft SharePoint once you have it installed in your environment and that the licensing costs flies away. An interviewed CTO states that companies he met don’t have control of their SharePoint installations and that they had to step back and look at the ownership and licenses.

    The article has some substance, but is is only viewed from one point.

    First of all one thing I agree with and that I have experience of - SharePoint installation madness. SharePoint is a complicated product/application/platform and should not be installed or launched if you do not have time or experience of it, period. You should have someone to help you out with these projects so that you have control of your installation, storage, security, governance etc etc. Planning - this is the most basic rule of any SharePoint installation.

    Second to think of is the article byline: “Once SharePoint, always SharePoint”. This is in the article read with a negative emphasis. If you invest and plan a SharePoint installation you should of course look into the future, but that future is probably not measured in months it’s most probably the platform you company will use over a foreseeable future. Once again the keyword here is Planning, and this has nothing to do with the platform. Every platform of this magnitude; WebSphere, Alfresco, DotNetNuke whatever you choose requires that you plan your installation and maintenance.

    If you one day discover that you need to change platform, this will cost and take time, independent of your choice of platform. Just make sure that it’s well documented and supports standards. SharePoint currently supports several standards, it will support the new CMIS (Content Management Interoperability Services) and thanks to Microsoft's new openness it’s quite well documented.

    Pricing and licensing is always a tough area to discuss. Yes, using SharePoint will cost you in server licenses and CALs but it’s not more expensive than comparable competitors. If you want to publish a web site and use all the powerful enterprise features of SharePoint you can’t expect the licenses to be the same as for a simple CMS system, in that case you choose the wrong platform to start with - Planning.

    I truly believe that if you invest in SharePoint you will definitely have a platform that you will use for a long time and not wanting to phase out.

  • Sweden SharePoint User Group meeting 9th of February 2009

    Tags: SharePoint

    The Sweden SharePoint User Group had the first meeting of this year this evening and it was a great and interesting meeting. I really enjoyed the session by Rickard Löfberg from Credit Suisse when he talked about their globally rolled out collaboration platform, how they handled the massive amounts of data and customized the platform to have a smooth transition to upcoming versions of SharePoint.

    I did two short sessions; one about Web Part development with 10 tips and a very short introduction to the Geneva Framework. You can find the presentations for download below, currently in Swedish - but if you beg I can finish up the translation to English.

    * I did two updates to the slide; corrected the sentence about Web Part connections and added a note on CAS, which we discussed.

    I’m now looking forward to the next meeting.

  • SPDiag - a SharePoint IT-Pro necessity

    Tags: SharePoint

    The latest version of the SharePoint Administration Toolkit has been released and it contains a new feature called SPDiag (SharePoint Diagnostics Tool).

    It’s a new tool for IT-Pros (or admins and developers for that matter) that helps you have a look at all of your SharePoint server (including hardware) configurations in a nice application. You can check everything from log file locations to web.config content to database configurations to…

     SPDiag

    imageYou have two views, one tree view in which you can drill down in your server/farm configuration and read all of the data and one Trends view in which you analyze and examine the usage of your farm and sites using the different logs in SharePoint and Windows. Unfortunately I did not get the graphs to show on my test machine (yes it’s a Windows 7 with WSS :-), see error message on the right.

    I don’t see this as just a IT-Pro tool, I think it will be great for developers when debugging and looking for problems, since you have a great view of the log files.

    Anyway, I guess you would like to download it all now…

  • Swedish SharePoint bloggers master feed

    Tags: SharePoint

    For the SharePoint Community Sweden community site I have created a master feed containing interesting blog feeds from Swedish SharePoint bloggers, with posts both in Swedish and English.

    This master feed can be found at: http://pipes.yahoo.com/wictorwilen/spcs_all?_render=rss

    Add this feed to your subscriptions if you are interested about how we Swedes think and elaborate on SharePoint.

    It’s built using the amazing Yahoo Pipes.

  • Web Part Properties - part 5 - localization

    Tags: SharePoint, Web Parts

    If you are building a reusable web part that you would like to sell or give away you should look into localizing your web part. The localization support is great with .NET 2.0, using resource files, and there are tons of built-in functionality for this. If you are creating an Editor Part for you web part, then your life is pretty easy, just use the standard techniques. But if you are using the approach by tagging the properties of your web part with the Personalizable attributes, then you are out of luck. Take a look at this property for example:

      1: [WebBrowsable]
    
      2: [Category("Look and feel")]
    
      3: [WebDisplayName("Use custom palette")]
    
      4: [WebDescription("Check this to use a custom palette")]
    
      5: [Personalizable(PersonalizationScope.Shared)]
    
      6: public bool UseCustomPalette {
    
      7:     get;
    
      8:     set;
    
      9: }
    
     10: 

    All these attribute values are hardcoded into you assembly, and you have to build different assemblies for different languages.

    Fortunately the .NET framework is extensible so you can extend these attributes (Category, WebDisplayName and WebDescription) so they take advantage of the localization features.

    All we have to do is to implement three classes: LocalizedCategoryAttribute, LocalizedWebDisplayNameAttribute and LocalizedWebDescriptionAttribute.

    They basically look the same and here is the code for LocalizedWebDisplayNameAttribute:

      1: [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    
      2: public sealed class LocalizedWebDisplayNameAttribute
    
      3:     : WebDisplayNameAttribute {
    
      4: 
    
      5:     bool m_isLocalized ;
    
      6: 
    
      7:     public LocalizedWebDisplayNameAttribute(string displayName)
    
      8:         : base(displayName) {
    
      9:     }
    
     10: 
    
     11:     public override string DisplayName {
    
     12:         get {
    
     13:             if (!m_isLocalized) {
    
     14:                 this.DisplayNameValue = 
    
     15:                     Resources.ResourceManager.GetString(
    
     16:                         base.DisplayName, Resources.Culture);
    
     17:                 m_isLocalized = true;
    
     18:             }
    
     19:             return base.DisplayName;
    
     20:         }
    
     21:     }
    
     22: }
    
     23: 

    What we do here is to override the DisplayName property and instead of just returning the value, we use the ResourceManager object and retrieve the value from our localized resources.

    After this we can change our original property code to something like this:

      1: [WebBrowsable]
    
      2: [LocalizedCategory("LookAndFeel")]
    
      3: [LocalizedWebDisplayName("UseCustomPalette")]
    
      4: [LocalizedWebDescription("UseCustomPaletteDesc")]
    
      5: [Personalizable(PersonalizationScope.Shared)]
    
      6: public bool UseCustomPalette {
    
      7:     get;
    
      8:     set;
    
      9: }

    To get this to work just add the three attribute values (LookAndFeel, UseCustomPalette, UseCustomPaletteDesc in the sample) to our resource file and you are set and done.

  • 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:

    Sample

    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: http://www.sharepointforum.com/SharePointUserGroup/default.aspx

    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.

    Background

    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 http://schemas.microsoft.com/WebPart/v3 schema and the .dws file uses http://schemas.microsoft.com/WebPart/v2. 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.

    Structure

    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.

    Sample

    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="http://schemas.microsoft.com/WebPart/v3">
    
      4:     <metaData>
    
      5:       <type name="TweetPart.TwitterWebPart, TweetPart, Version=1.0.0.0, 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.

    Summary

    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.

    Summary

    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))) {
            m_lbModes.Items.Add(mode);
        }
        this.Controls.Add(new LiteralControl("<b>Mode</b><br/>"));
        this.Controls.Add(m_lbModes);
        this.Controls.Add(new LiteralControl("<br/><b>Username</b><br/>"));
        this.Controls.Add(m_tbUsername);
        this.Controls.Add(new LiteralControl("<br/><b>Search string</b><br/>"));
        this.Controls.Add(m_tbSearchString);
    
        base.CreateChildControls();
        this.ChildControlsCreated = true;
    }

    SyncChanges

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

    public override void SyncChanges() {
        EnsureChildControls();
        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;
        }
        return;
    }

    ApplyChanges

    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() {
        EnsureChildControls();
        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";
        editors.Add(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.

    First...

    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";
        this.Controls.Add(m_editorPanel);
    
        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.Items.Add(mode);
        }
        m_lbModes.AutoPostBack = true;
        m_lbModes.SelectedIndexChanged += new EventHandler(m_lbModes_SelectedIndexChanged);
        m_modesPanel.Controls.Add(m_lbModes);
        m_modesPanel.Controls.Add(new LiteralControl("</nobr></div></div>"));
        m_editorPanel.Controls.Add(m_modesPanel);
    
        m_searchPanel = new Panel();
        ...
        m_editorPanel.Controls.Add(m_searchPanel);
    
    
        m_usernamePanel = new Panel();
        ...
        m_editorPanel.Controls.Add(m_usernamePanel);
    
        ...
    }

    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.

    Final...

    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.

    Configuring...

    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:

    [WebBrowsable]
    [WebDisplayName("User name")]
    [WebDescription("The Twitter Username")]
    [Category("Twitter")]
    [Personalizable(PersonalizationScope.User)]
    public string Username {
        get;
        set;
    }

    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:

    [WebBrowsable]
    [WebDisplayName("Tweet count")]
    [WebDescription("Number of tweets to show")]
    [Category("Twitter")]
    [Personalizable(PersonalizationScope.Shared)]
    [WebPartStorage(Storage.Shared)]
    public int TweetCount {
        get;
        set;
    }

    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...