Thursday, July 8, 2010

MOSS 2007: Get Shared Services User Profile without “Manage User Profile” permission

For a custom functionality I’m developing for my customer I needed to retrieve the user profile logged on the application. To accomplish this task SharePoint object model provides the class UserProfileManager which allows you to query user profile properties.

There is only a tip when you write your code to access the user profile properties, in fact you can use two different piece of code to accomplish that:

  1. if you instance a new UserProfileManager (see the commented code below on 7th row) you could have problem and receive the following error:

    “You must have manage user profiles administrator rights to use administrator mode.”

    This is due to the fact that to instance a UserProfileManager you need administration right on SharePoint Shared Service.
  2. Instead of the creation of a new instance of UserProfileManager class, you can get an already present instance using ProfileLoader class (see row 8, 9 and 10 below). In this way you can access to a read-only version of UserProfileManager class which permits you to query every properties of the user profile you have requested (see all the example below).
   1:  public UserProfile GetUserProfile(string loginName)
   2:  {
   3:      UserProfile userProfile;
   4:      using (var Site = new SPSite(SiteId))
   5:      {
   6:          var ctx = ServerContext.GetContext(Site);
   7:          //var upm = new UserProfileManager(ctx, true);
   8:          var profile = ProfileLoader.GetProfileLoader(ctx);
   9:          var upm = profile.GetUserProfileManager();
  10:          var spUserProfile = upm.GetUserProfile(loginName);
  12:          userProfile = new UserProfile(spUserProfile.ID)
  13:            {
  14:                Login = loginName,
  15:                PreferredName = spUserProfile["PreferredName"] != null ? 
  16:                  spUserProfile["PreferredName"].Value as string : string.Empty,
  18:                Manager = spUserProfile["Manager"] != null ? 
  19:                  spUserProfile["Manager"].Value as string : string.Empty,
  21:                Name = spUserProfile["FirstName"] != null ? 
  22:                  spUserProfile["FirstName"].Value as string : string.Empty,
  24:                Surname = spUserProfile["LastName"] != null ? 
  25:                  spUserProfile["LastName"].Value as string : string.Empty
  26:            };
  28:      }
  30:      return userProfile;
  31:  }


Particular thanks to my friend Michele who supported and suggested me on how to resolve this problem.

kick it on
Save to delicious 0 saves

TFS 2010: TF270015: 'MSTest.exe' returned an unexpected exit code. Expected '0'; actual '1'.

If you try to build an “old” Visual Studio 2008 solution with the new Team Foundation Server 2010 and after the build you try to execute automatic unit test project inserting the following directive inside your build project:

<MetaDataFile Include="$(BuildProjectFolderPath)/&lt;your vsmdi file>.vsmdi">

your build probably will fail with the following nice error:

TF270015: 'MSTest.exe' returned an unexpected exit code. Expected '0'; actual '1'.

After a Google search (see references below) I’ve found that the problem could be due to the fact that TFS 2010 can only build test project written in .NET 4.0.

For now there’s no fix available to resolve this problem (as you can see here) and there’s no timing about a Microsoft hotfix (QFE) release.


kick it on
Save to delicious 0 saves

Wednesday, July 7, 2010

MOSS 2007: “The evaluation version of Microsoft Office SharePoint Server 2007 for this server has expired”

If you receive this error when you try to access to SharePoint Shared Service on your machine, don't panic. It's a problem due to SP2 installation. You can find more detail and hotfix about this problem here.



kick it on
Save to delicious 0 saves