Thursday, February 24, 2011

List instance data is deployed asynchronously

Suppose you have SharePoint list instance that is deployed to site using feature. Also suppose this list instance has event receiver bound to it. Add some debug messages to event receiver, run your project and activate feature through SharePoint web interface. From output you should see that items are added to list on more than one thread.

Example data

I have unique values for one field and these values are hierarchical. Example of values is here:


9
9.1
9.2
10.1
10.2
10.2-1

There are about 250 rows of data defined in list instance definition.

Asynchronous creation of list items

When I run my SharePoint solution using Visual Studio 2010 and activate list instance feature through web interface then I can see the following about in Visual Studio debug window:

SharePoint: List instance data is inserted asynchronously

Note the random order of ID-s – in list instance definition rows are ordered correctly. Also note that there are threads with different ID-s that are closed when data is inserted.

Feature is activated before items are inserted

One interesting thing I also noticed is that feature is activated and browser is already returned to features page but inserts still continue. I faced some situations when data gets fully inserted about one minute after activating the feature.

You should very carefully handle situations where you have event receiver bound to automatically filled list and your receiver expects full data to be already there. Also you should be careful when your receiver expects that data is inserted in same order as it appears in list instance definition.

Saturday, February 19, 2011

Could not load file or assembly CabLib or one of its dependencies

When using WSPBuilder from command line you may get the following error: “Could not load file or assembly 'CabLib, Version=10.2.0.0, Culture=neutral, PublicKeyToken=5c838b77b53f84a0' or one of its dependencies. An attempt was made toload a program with an incorrect format.” This error occurs if there is something wrong with CabLib.dll or if CabLib.dll doesn’t exist in same folder with WSPBuilder.

Steps to fix:

  1. Make sure CabLib.dll is in same folder with WSPBuilder.exe
  2. Make sure you have correct version of CabLib.dll (32bit or 64bit)

On 64bit virtual server I replaced the old CabLib.dll with 64bit version and I got this error solved.

The program w3wp.exe, with the assigned process ID, could not authenticate locally by using the target name HTTP/WEBSITENAME.

You may face this error when you are running your development environment on virtual server where you have also configured alternate access URL-s.The full message is something like this:

The program w3wp.exe, with the assigned process ID, could not authenticate locally by using the target name HTTP/WEBSITENAME. The target name used is not valid. A target name should refer to one of the local computer names, for example, the DNS host name.

Try a different target name.

applocix blog posting w3wp.exe unable to authenticate on target name helps us out:

  1. Go to REGEDIT and open the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
  2. Right click MSV1_0 –> New -> Multi-String Value
  3. Type BackConnectionHostNames and click Enter.
  4. Right click on newly created value and select Modify.
  5. Enter the hostname of the site: WEBSITENAME (and on a new line enter the FQDN, WEBSITENAME.domain.com)
  6. Restart IIS

This way I got my internet zone host name work on my virtual server.

Friday, February 18, 2011

SharePoint 2010 exams and measured skills

There are four exams for SharePoint 2010:

Here are the requirements for these exams. Just made a short list to keep myself better on my SP2010 education track.

70-573: TS: Microsoft SharePoint 2010, Application Development

  • Working with the SharePoint User Interface (19%)
  • Developing Web Parts and Controls (21%)
  • Developing Business Logic (19%)
  • Working With SharePoint Data (22%)
  • Stabilizing and Deploying SharePoint Components (19%)

70-576: PRO: Designing and Developing Microsoft SharePoint 2010 Applications

  • Creating an Application Design (19%)
  • Designing UX (17%)
  • Managing Application Development (18%)
  • Optimizing SharePoint Application Design (15%)
  • Designing SharePoint Composite Applications (13%)
  • Designing SharePoint Solutions and Features (18%)

70-667: TS: Microsoft SharePoint 2010, Configuring

  • Installing and Configuring a SharePoint Environment (25%)
  • Managing a SharePoint Environment (26%)
  • Deploying and Managing Applications (24%)
  • Maintaining a SharePoint Environment (25%)

70-668: PRO: Microsoft SharePoint 2010, Administrator

  • Designing a SharePoint 2010 Farm Topology (27%)
  • Planning SharePoint 2010 Deployment (26%)
  • Defining a SP2010 Operations Strategy and Business Continuity (25%)
  • Planning for Search and Business Solutions (22%)

Sunday, February 13, 2011

Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. You don't have Add and Customize Pages permissions required to perform this action.

After deploying your solution to SharePoint anonymous and read-only users may get the following error: Web Part Error: A Web Part or Web Form Control on this Page cannot be displayed or imported. You don't have Add and Customize Pages permissions required to perform this action. Well, this is the case that is solved by famous this-issue-is-by-design (read: you have to find your own way how to solve the problem).

Why this error occurs?

The error message sais directly what is the problem: the current user has no permissions to customize pages and add or modify web parts on it. If you just deployed your solution to server and your solution is also accessible for anonymous and read-only users then they will get this error when accessing the page.

If you access the page as administrator then all web parts are put on page like expected because you have enough permissions to do it. After you opened page as administrator and you open same page as read-only or anonymous user the error is gone. This is because administrator account has enough permissions for all page initializing operations that must be done when page is accessed first time.

How to solve it?

Make sure your web parts are marked as safe in web.config file. There is special site level permission called “Add and Customize Pages” and by default this permission is not applied to Contributor role. You can do it manually through site settings page. This is not good option because now your contributors have more permissions you may want to give them.

Second option is go through site as administrator and open all pages that have custom web parts. If you don’t have a lot of pages and opening all pages is not very time consuming you can also consider this option.

If you have more pages and they are created during deployment and you know URL-s of pages you can write PowerShell script that requests all those pages as administrator to get pages initialized under account that has enough permissions to do so. You can also consider using wget or some similar command-line tool to make those requests.

Right now I don’t have more information about how to solve this issue. In my case the third option is best one because I have to provide my users a way how they can deploy solution and initialize it so they don’t have to go through a lot of configuration steps. If I find some better solution how to solve this issue I will blog about it here.

Wednesday, February 9, 2011

Get all items under SPFolder

This is how to get all items from current SPFolder.


var query = new SPQuery { Folder = folder };
var items = list.GetItems(query);


Note that you don’t have to assign Query property of SPQuery.

Tuesday, February 8, 2011

PublishingWeb.CurrentNavigationNodes property is gone in SharePoint 2010

In SharePoint 2007, PublishingWeb has property called CurrentNavigationNodes. It is gone in SharePoint 2010 and you can find it from the following location:

publishingWeb.Navigation.CurrentNavigationNodes

publishingWeb here is instance of PublishingWeb.

Wednesday, February 2, 2011

SharePoint local farm is not accessible from PowerShell

Another error related to database permissions occurs when opening SharePoint PowerShell console: “The Local Farm Is Not Accessible. Cmdlets With FeatureDependencyId Are Not Registered.”

To fix this error register your console user account as user in content database. I added my shell account user to dbo role in content database and problem was solved.

Add-SPShellAdmin–user cannot exist in database

If you try to add user to SharePoint shell administrator role you may get the following error: "Cannot add <user> to the SharePoint_Shell_Access role of the database SharePoint_Config_<Guid>. A possible cause of this error is that the account name was already added to the database as a login using a different user name than the account name."

If user is database user through dbo role and it has not added to shell admin role then the username does not appear in shell administrators list if you run Get-SPShellAdmin. You cannot add this user to shell administrator role using Add-SPShellAdmin. Also adding user to SharePoint shell access role in database gave no results.

Here’s how I solved it:

  1. Connect to SharePoint config database using Management Studio
  2. Open SharePoint config database
  3. Change database dbo using the following command:
    sp_changedbowner @loginame=some_other_user'
  4. If there were no errors then in SharePoint PowerShell console run Add-SPShellAdmin again

I don’t know why Add-SPShellAdmin is not able to add existing dbo user to shell access role. Going through steps given here I was able to solve the problem.

SharePoint farm administrator have no permissions to run PowerShell commands

On SharePoint 2010 it is not enough if you are farm administrator. You still cannot run PowerShell commands sometimes. The reason is simple – your user account needs more permissions. Here’s how to add permissions.

  1. Open SharePoint 2010 PowerShell console as administrator
  2. Type: Get-SPShellAdmin
  3. Make sure your user account is not in the list of shell administrators
  4. Type: Add-SPShellAdmin –username <your username>
  5. Type: Get-SPShellAdmin
  6. Your newly added username should now exist in the shell admins list

Now you can run your PowerShell scripts from your farm administrator (or any other) user account.