Friday, October 8, 2010

Export and import of list does not move permissions and security

My requirement was to migrate a list with more than 3000 records and many folders from one site collection to another. Both the list and its folders had unique permissions assigned to it.

My first attempt was to save the list as template with data, and to create the list in my target site using the template. The list was migrated along with its data, but permissions on the list were not. The new list was still inheriting permissions from the parent site.
I then tried using the power shell command "export-spweb", since this command had a parameter "-IncludeUserSecurity", which when set, was supposed to move the list along with the permissions. However, this did not work out either. Looks like a bug with the command.

Resolution:

The solution that worked for me was to use a power shell extension cmdlet developed by Gary Lapointe, a Microsoft MVP.

Here are the steps:

1)  Download and deploy the Cmdlet WSP from here http://stsadm.blogspot.com/2009/02/downloads.html

2)  Use the following power shell commands to deploy the extensions:

Add-SPSolution C:\xxxx\Lapointe.SharePoint2010.Automation.wsp
Install-SPSolution -Identity Lapointe.SharePoint2010.Automation.wsp -GACDeployment

3) Once deployed, use the following command to migrate the list with permissions:

copy-splist -sourcelist "http://xxxx/lists/mylistname" -targetweb "http://xxxxxx/mysitename" -IncludeVersions All -IncludeDes
cendants All -IncludeUserSecurity

This worked like a charm!

Thursday, October 7, 2010

Anonymous access, CQWP and picture libraries

I had used a picture library to store the information to be displayed using a content query web part. It worked fine for authenticated users, but failed when the site was configured for anonymous access. The content query web part failed with the following error, when viewed by anonymous users:

Error while executing web part: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart.SetDocumentIconUrlAndOnClickString(SPWeb web, DataRow row, String strDefaultItemOpen, Boolean fSetDocIcon, Boolean fSetOnClick, String fileRefColumnRef, String progIdColumnRef, String fsobjTypeColumnRef, String permMaskColumnRef)..


Resolution:

Investigating the method, SetDocumentIconUrlAndOnClickString using reflector, I found this line of code which would result in this exception for anonymous users:

builder.Append(StrJScriptParameter(Convert.ToString(web.CurrentUser.ID, CultureInfo.InvariantCulture), true));

When I was about to override this behavior by code, I found a more elegant non-code solution on the web. The solution was to export the web part and add the following to the commonviewfields property:

<property name="CommonViewFields" type="string">DocumentIconImageUrl;OnClickForWebRendering</property>

This solved the problem.