Tuesday 7 December 2010

Amending the Welcome Menu

Problem: Welcome Menu or Personal Actions Menu occasionaly refered to as the User Menu. SharePoint 2010 that displays the users name in the Welcome server control, this by default in the top right of the master page.  You can add new menu items or hide existing menu items.
Initial Hypothesis
  • The Welcome user control is located in the 14 hive at 14\TEMPLATE\CONTROLTEMPLATES

  • The user control is reference in master pages.
  • Take a copy of the welcome.ascx file as you will be working on the original or need to reference your new copy in your master page.
Resolution: Hide the menu option in the Welcome Menu.
Use the PermissionString property to dispay the menu option depending on your permissions.
Edit the Welcome.ascx file for each menu option element add the visible attribute and set it to false to hide the menus.
List of valid properties for the PermissionsString property
Alternatively set the MenuItemTemplate attrivute visibility to false, this will hide the menu option for everyone.
 
Resolution - Another option for changing the welcome control:
  • Remove the server control wssuc:Welcome from the master page or set it's visibility to hidden.
  • Then write a Replacement control and add it to the master page.

 Resolution:  Add a new menu item
  • Add a new element to the project that will be deployed as a feature

  • Add the following code to the element file

 

  •  New menu item (Open BBC) is add to the welcome menu.

 

More Info:
http://glorix.blogspot.com/2007/08/custom-action-locations-and-groupid.html
http://www.sharepointnutsandbolts.com/2007/07/using-customaction-to-modify-system.html
http://blog.thekid.me.uk/archive/2007/06/23/sample-editcontrolblock-customaction-for-sharepoint.aspx

How to Hide Ribbon
http://blogs.msdn.com/b/zwsong/archive/2010/04/29/how-to-hide-ribbon-from-users-without-edit-page-privilege.aspx

Chris O'Briens Ribbon Customisation blog series
http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html

Sunday 5 December 2010

Sandboxed Solution with Full Trust Proxy

Problem: You deploy code as a sandbox solution however it fails as you need to go beyond the permissions a sandboxed solution can perform.  For example sandbox solution code cannot write to the ULS and security is restricted so you won't be able to use RunWithElevatedPrivileges.

Resolution: You can develop a full trust proxy that is deployed into the GAC, you also need to register the full trust with SharePoint.  Lastly, create the code for your sandboxed solution using the Full Trust Proxy code.  The full trust proxy performs the operations that are beyond what the sandbox solution code is allowed to perform.
Update 23 April 2011 - CKSDev is an extension tool for Visual Studio that has a SPI (template) to create a full trust proxy.  This will do all the plumbing of creating the full trust proxy and the deployment packaging.  So if you are wanting to add a Sandbox Solution Full Trust Proxy for Logging use the VS template provide and all you need to add is your logging code.

More Info:
http://blah.winsmarts.com/2009-12-SharePoint_2010_Sandboxed_Solutions__Full_Trust__Proxies.aspx
http://ranvijaysingh.blogspot.com/2010/06/full-trust-proxy-in-sharepoint-sandbox.html

Thursday 2 December 2010

Error occurred in deployment step Activate Features Failed to activate feature .. at scope

Problem: When deploying a soluction in VS 2010 I get the following error.

"VS Error: Error occurred in deployment step 'Activate Features': Failed to activate feature 'XX' (ID: xxxa2e8a-78d7-451c-aa85-3d28555e5555) at scope 'http://demo.dev'."
ULS contained the following error "Feature Activation: Threw an exception, attempting to roll back. Feature 'XX' (ID: 'xxxa2e8a-78d7-451c-aa85-3d28555e5555'). Exception: System.InvalidOperationException: Failed to activate feature 'XX' (ID:xxxa2e8a-78d7-451c-aa85-3d28555e5555) at scope 'http://demo.dev'. at Microsoft.SharePoint.SPFeature.HandleActivateError(SPFeature featError, Int32 iRetVal, Boolean fForce)"

Initial Hypothesis: Performing an IISreset did not resolve my issue, the suggestion to manual start the feature will activate the feature however it does not solve my deployment issue from VS. The feature is scoped at 'Site' level so activating the feature can be done at the site collection level.

Resolution: Removed the feature and solution using Powershell Rebooted Visual Studio development environment Open solution in Visual Studio 2010 and redeployed.  The cause is still not know however, rebooting and uninstalling the solution has fixed the issue.
More Info:
http://social.technet.microsoft.com/Forums/en-US/sharepointadmin/thread/ee35db1a-b83f-477e-ba6b-f59ac8522e34/

The parent content type specified by content type identifier ... does not exist

Problem: When I deploy a solution that automatically activates a feature I receive the following error "Error occurred in deployment step 'Activate Features': The parent content type specified by content type identifier 0x0120D520 does not exist.".
Initial Hypothesis: The feature being deployed relies on another feature being activated, in this case it is the 'Document Sets' site collection feature that is missing.
Resolution: Site Settings > Site Collection features > Document Sets (Activate)
More Info:
http://msdn.microsoft.com/en-us/library/aa543822.aspx

Cannot insert duplicate key row in object

Problem: Error occurred in deployment step 'Add Solution': Cannot insert duplicate key row in object 'dbo.Solutions' with unique index 'Solutions_BySiteAndSolutionId'.

Initial Hypothesis: Sandbox solution wsp deployment is causing the error. I delete and created a new site collection with an identical url.

Resolution: Using Visual Studio 2010 in the solution browser, select the project that is not deploying. In the properties window change the 'Site URL' property that tells Visual Studio the site to deploy your project code to. Change the 'Site Url' to something else save the change and then change the 'Site Url' property back to its original value.  Redeploy the project and it deploys correctly.  Thanks to Brian Farnhill.
Read More:
http://blog.brianfarnhill.com/2010/11/16/error-cannot-insert-duplicate-key-row-in-object-dbo-solutions/

Monday 29 November 2010

SPMetal Extender CodePlex project

I have release a project on codeplex, SPMetal Extender to be able to use additional field types.  Fields in lists can be extended using partial classes.  The project provides a Visual Studio plug-in vsix that generates Linq to sharePoint code for unsupport list fields such as publishing fields.  Additionally the vsix deploys a new template showing how to add 4 additionaly properties to SPMetal.  The Item template is guidance and needs to be adjusted by the developer after it is created.
SPMetal Extender VSIX extension installed
Add a new SPMetal Extended item to a SharePoint project
Generate code for addionnal list fields using Server Explorer using the VS IDE

SPMetal Extender is also published on Microsoft Visual Studio tools gallery 

Saturday 27 November 2010

Error adding webpart containing validation control

Problem: When adding a custom built webpart with asp validator controls to a page, the user will encounter the following error when attempting to save the changes "Error: This page contains content or formatting that is not valid.".
Initial Hypothesis:
This error only happens when the webpart control has validators and prevents the user being able to add the webpart to the page.

Resolution: Disable the validator controls when editing the page.
Add the following public method in the server control code ...
public void EnableValidators(bool enableVal)
{
this.validatorName.Enabled = enableVal;
}
In the Webpart's CreateChildControls() procedure only add the user control/validation when not in edit mode
if (SPContext.Current.FormContext.FormMode == SPControlMode.Edit || SPContext.Current.FormContext.FormMode == SPControlMode.New)
{
//validator.enabled = false
((UserControl1)_ctl).EnableValidators(false);
}
else
{
//validator.enabled = false
((UserControl1)_ctl).EnableValidators(true);
}
}
Add the EnableValidators method to the user control code behind:
 
The validators will then be disabled when adding the web part​ to the page / editing the page, but still work in presentation mode.

Thanks to Paul W