SocialTagManager and Private Social Tags in SharePoint 2010

A couple of days ago I was working on a WebPart for a clients Intranet which should display a list of pages which the user has tagged as “Saved pages”. I was somewhat surprised to discover that there was no public method available which returns private social tags. The only way was to use Reflection to call the internal scoped overloaded method SocialTagManager.GetTags() which has a Boolean parameter called “includePrivate”. This issue has been discussed previously in a couple of places:

Earlier tonight I was reading through the issues fixed in the February 2012 Cumulative Update for SharePoint Server 2010 and saw this item at the bottom of the list:

“The public GetTags methods of the SocialTagManager class do not retrieve private tags.”

Since I had code using this method ready I fired up my development machine to install the CU and test if this was true. And of course it was, and here is the proof illustrated by using .NET Reflector.

before-feb-2012-cu
- Before Feb 2012 CU

after-feb-2012-cu
- After Feb 2012 CU

As you can see in the code above the “includePrivate” parameter could now be true, if the provided UserProfile represents the current user. Before installing the CU the method was always called with the value false.

IMPORTANT: Always test updates in non-production environments before deploying them to production. In the past updates have caused some problems for customers. Read about some history here, here and here.

That’s it for this time. Happy coding everyone.

Currently rated 1.6 by 154 people

  • Currently 1.597403/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Managed Metadata Service Application Time-outs

Recently I was making some updates on a customers application where we have set up a provisioning script which allows us to build up and tear down the portal quickly to test the provisioning of the whole portal, and the provisioning of web templates used for sub sites inside the portal.

While making some updates on provisioning code for the web templates I executed the provisioning script, which has worked for the last few months without any issues. Today it didn’t though. During provisioning of the portal a site collection feature is activated which checks that the dependent service application instances are created and configured according to specification. While checking the settings of the associated Managed Metadata Service Application some errors occurred and the provisioning was stopped and rolled back as a result of the error.

When setting up this development environment for the first time I had similar issues with the provisioning code, which turned out to be related to missing permissions on the service application instance. Naturally this was where I started looking this time, but found nothing wrong with the settings.

After some time of frustration I dove into the ULS log and started backtracking what was happening inside SharePoint as a result of me running the following code:

image

The TaxonomySession.DefaultKeywordTermStore property returns null in one case that is documented in the remarks section this MSDN article. But the documentation did not help in this case.

When I looked into the ULS log I discovered this error though:

Exception returned from back end service. System.TimeoutException: The request channel timed out while waiting for a reply after 00:00:29.9949985…

That was pretty straight forward and with the help of this Technet article, under the section TimeoutException, I could adjust the timeout values to 1 minute instead of the default 30 seconds. This solved the issue and my provisioning code could run. The default location of this file on a SharePoint machine is C:\Program Files\Microsoft Office Servers\14.0\WebClients\Metadata\client.config

image

I’m not sure yet of the reason why this happened on my development machine, but since it is a development machine I don’t feel too worried about the adjusted configuration. I would not recommend the same adjustment on a production environment. Start by finding the root cause for the time-out instead and try to fix it rather than adjusting the web client settings.

Merry Christmas and Happy New Year…

Currently rated 1.6 by 53 people

  • Currently 1.603774/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Ask Windows Search Service When Developing SharePoint 2010 Applications

Today I thought I’d share one of my development tips. Developing applications on SharePoint is often best done by leveraging out-of-the-box functionality to the highest extent possible. When discovering out-of-the-box functionality it can be challenging to find what you are looking for, especially when searching for feature definition that you stumble upon inside site definition onet.xml files. Here is a snippet from the BLANKINTERNET onet.xml file:

<WebFeatures>
  <Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
    <!—Publishing –>
    <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
      <Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/nightandday.master"/>
      <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/default.aspx"/>
      <Property Key="PagesListUrl" Value=""/>
      <Property Key="AvailableWebTemplates" Value="*-BLANKINTERNET#2;*-ENTERWIKI#0"/>
      <Property Key="AvailablePageLayouts" Value=""/>
      <Property Key="AlternateCssUrl" Value="" />
      <Property Key="SimplePublishing" Value="false" />
    </Properties>
  </Feature>
</WebFeatures>

This is a hidden feature which is activated as a part of the site provisioning process when you create a Publishing Portal (BLANKINTERNET#0) site. Although this feature is not so hard to find since we can see the name of it in the comment, but not every feature reference in onet.xml files are this well commented. Like this one for example:

<SiteFeatures>
  <!-- "A44D2AA3-AFFC-4d58-8DB4-F4A3AF053188" –>
  <Feature ID="A44D2AA3-AFFC-4d58-8DB4-F4A3AF053188" />
</SiteFeatures>

Sure, you could run the following Powershell CmdLet to find the name of the feature:

Get-SPFeature | Where { $_.Id -eq "A44D2AA3-AFFC-4d58-8DB4-F4A3AF053188" }

But personally I prefer using Windows Search to find the feature. When you are developing for SharePoint you are most likely working on Windows Server 2008 R2 where Windows Search is not enabled by default. To make this feature available you have activate the role service Windows Search Service, which requires the File Server role.

When Windows Search is enabled, and your 14 Hive has been indexed you can search the FEATURES folder to get a result like this:

image

From this view you can easily find the file named feature.xml, and right click it to open the file location and open the file. The feature.xml file will tell you most of the thing you need to know about how a feature work, and how you can use it for your own applications. This is also where .NET Reflector is your best friend. From the feature.xml file you will find the assembly and the class which contains the FeatureActivated method holding all the secrets. Here is an example from the Publishing feature above:

<Feature
  Id="22A9EF51-737B-4ff2-9346-694633FE4416"
  Title="Publishing"
  ReceiverAssembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
  ReceiverClass="Microsoft.SharePoint.Publishing.PublishingFeatureHandler">
</Feature>

By finding the FeatureActivated method in the above referenced class Microsoft.SharePoint.Publishing.PublishingFeatureHandler in the also referenced assembly Microsoft.SharePoint.Publishing you will find the could which tells you what the feature does and where each setting ends up as a result of using feature properties when activating it. Sometimes you can also discover other properties while looking at the FeatureActivated method.

I hope this tip is helpful. It sure has saved some time for me. Cheers.

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Always check your code for improper disposal or lack of disposal

Recently I was involved in a short assignment for a one of our clients which involved fixing some of the issues that they were experiencing with their newly released corporate intranet built on SharePoint Server 2010. During this assignment I once again stumbled upon code with handles unmanaged objects incorrectly. Most developers working with SharePoint nowadays know about the effects of not handling SPWeb and SPSite object correctly, but still mistakes are made which can lead to potentially horrible effects.

Disposing of object fetched from SPContext like this:

using(SPWeb currWeb = SPContext.Current.Web)
{
//Do something
}

...can lead to crashes later during the request since other code might rely on this object not being disposed.

Forgetting to dispose objects created in your code, or fetched from a collection of objects, can lead to memory leaks which can both crash your application and make it perform generally bad. Example:

SPSite site = new SPSite(http://urltothesite);
foreach(SPWeb web in site.Webs)
{
//Do something
}

I personally consider these issues mainly as rookie mistakes, and it should be considered a hygiene factor to work with these object in the proper manner. Instead of writing a whole article about how to prevent these mistakes from reaching a production environment, I'm simply gonna link to an article written by my friend Tobias Zimmergren (SharePoint Server MVP) who goes through the topic in more detail, supplies good links and demostrates the primary choice of tooling (SPDisposeCheck) that will help you identify and fix your mistakes.

Let's face it, even awesome SharePoint developers make mistakes sometimes, but not having the proper tooling incorporated in your development environment is an unforgivable mistake.

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SharePoint 2010 MCTS Pratcice Tests from MeasureUp are released

For those out there looking to get MCTS certified on SharePoint 2010, MeasureUp has realesed practice tests that help you with this. With experience from MOSS 2007, this is a pretty good way to study for the MCTS certifications.

Currently rated 3.3 by 6 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Classroom tips and links - M10174 Stockholm 2008-09-27

This post is made up of tips and links to the students who attended the M10174 at Addskills in Stockholm which I'm teaching Sep 27th - Oct 1st  2010. Of course if could be of use to others aswell.

SharePoint 2010 - Scripted install through Windows Powershell on Technet:

Why not to use Windows 7 on development machines by Todd Carter:

Guide to User Profile Service Application by Spencer Harbar:

Mulit-Tenancy in SharePoint 2010 by Specer Harbar (7 parts):

  1. http://www.harbar.net/articles/sp2010mt1.aspx
  2. http://www.harbar.net/articles/sp2010mt2.aspx
  3. http://www.harbar.net/articles/sp2010mt3.aspx
  4. http://www.harbar.net/articles/sp2010mt4.aspx
  5. http://www.harbar.net/articles/sp2010mt5.aspx
  6. http://www.harbar.net/articles/sp2010mt6.aspx
  7. Not yet published

SharePoint 2007/2010 Scripting with STSADM and Powershell by Gary Lapointe:

Good White Papers on Technet:

Disable UAC on Windows Server 2008 R2

SharePoint 2010 Evaluation and Demostration VM

Site Collection Keep Alive Jobs by Andrew Connell:

Collection of good links for certifications, online training etc by Razi:

Planning Worksheets on Technet:

Useful tools:

Currently rated 2.7 by 3 people

  • Currently 2.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Custom User Profile Properties – Lessons Learned

Creating custom User Profile Properties in SharePoint 2010 is pretty well documented on MSDN. But they haven’t documented the limitations worth knowing yet. Recently I spent some time developing some sample code and stumbled upon some limitation that I thought I’d share.

Required steps for creating User Profile Properties

User Profiles Properties are created in three steps, as indicated on MSDN:

  1. Create a CoreProperty (Name, Description, Data Type etc.)
  2. Create a ProfileTypeProperty (Organization or User)
  3. Create a ProfileSubtypeProperty (Associate with a Profile Sub Type)

When creating a CoreProperty object there are a few properties on that class which needs to be assigned values:

  • CoreProperty.Name (string)
  • CoreProperty.DisplayName (string)
  • CoreProperty.Description (string, not mandatory)
  • CoreProperty.Type (string, use constants provided by the PropertyDataType class)
  • CoreProperty.Length (integer, mandatory for custom properties of type String)
Property Limitations

When assigning the above mentioned properties there are some limitations which are useful to know. The limitations are not documented anywhere but are pretty obvious when looking disassemble the CoreProperty class with .NET Reflector:

image

  • CoreProperty.Name (max 50 characters)
  • CoreProperty.DisplayName (max 50 characters)
  • CoreProperty.Description (max 512 characters = hexadecimal 0x200
Summary

These are limitations learned from creating simple User Profile Properties of data type SingleValueString and Boolean. I will update this post continually if I find more limitations for other data types.

I hope this is of help to someone. Cheers.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Error When Deploying Solution To SharePoint 2010 through Visual Studio 2010

Today I was working on a solution for SharePoint 2010 when I ran into a strange error message while trying to deploy my solution. The error message was this:

Error occurred in deployment step 'Recycle IIS Application Pool': Cannot connect to the SharePoint site: http://app01:9000/. Make sure that this is a valid URL and the SharePoint site is running on the local computer. If you moved this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the Site URL property of the project.

The reason why I got this is that I had recently refactored my solution by re-organizing some features and something went wrong in the development site I was using as a result of that. I tried a quick fix by deleting the web application where the development site was located and created it again with the same settings as the old one, but with a new content database. When trying to deploy my solution in the freshly created web application I received the error message. After some troubleshooting I found the problem. When developing SharePoint 2010 solutions you should make sure that your windows account has the following permissions:

  • Local admin in the development box
  • Farm admin in Sharepoint
  • Has db_owner (or sysadmin server role) on the content database for the develoment site
  • Is site collection administrator on the development site

Since I had created a new web application and therefore a new content database, the db_owner role was not set automatically on the new database. Setting the correct roles on the database in SQL Server fixed my problem and deployment is now working fine. This is something to look out for when developing a farm with separated service accounts.

I hope this is useful info for someone out there who is experiencing the same problem.

Currently rated 5.0 by 4 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

SharePoint 2010 Release in June

On the twitter page for SharePoint 2010 it says that the product will be released in June next year, and hopefully RTM in April. On this news search result page you can find many articles that strengthen the rumours about a June release for Office 2010 and related products, and some even confirming that Microsoft has confirmed the release plan. I'm convinced, June it is.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5