Tuesday, September 23, 2014

Resolving the error "You must specify a value for this required field" while trying to save and close a SharePoint webPart page

If you are working in a SharePoint project and at the time of working in a SharePoint page, starts getting an error stating "You must specify a value for this required field" at the time of saving the changes done to the page though you are sure you have all the webPart properties are set with right values, then check one more thing - are you using custom master page?

Many times when we design custom master page, we comment out the code block inside the master page which is responsible of showing the Navigation Breadcrumb inside the ribbon. That block is present under the div tag with id 's4-workspace' and with asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea".
So make sure this ContentPlaceHolder is not commented out. If you don't want it to appear in your master page, you can use the Style="display:none" function as shown below. Save it and go back to the page where you got the error and try to save it. You will see the page will be saved without throwing any error!

How to make SharePoint 2010 site logo to take you to the Root Site Collection Home Page

Many time we have got requests from end users and site owners to change the out of box site logo's behavior so that when they select it, it should take them to the home page of the root site collection. And this is a very fair request and the common behavior of most of the websites present in the internet. The default behavior of the SharePoint site logo is to take you to home page of the current site from where you have selected the logo. To change it open the Master Page of your site in Edit mode in SharePoint Designer. 
Search for the div id 's4-workspace'. Little inside that div you are going to find a Table Column with class 's4-titlelogo' and "SharePoint:SPLinkButton runat="server" NavigateUrl="~site/"... inside that column.
Just change the NavigateUrl property value to "~siteCollection/" and save and publish the master page.
Now go back to your site, navigate to any sub-site and from inside that sub-site, click on the site logo and you will notice it will take you to the home page of the root site collection. Thats it!

Thursday, September 4, 2014

How to resolve "The security validation for this page is invalid" error in SharePoint 2010

How to resolve "The security validation for this page is invalid" error in SharePoint 2010

It may possible many time when you are running custom code in SharePoint's context you are getting the following error:

Microsoft.SharePoint.SPException: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. ---> System.Runtime.InteropServices.COMException: 

This error can be thrown for different reason but the prominent one that I noticed is when some list/ library edit/ update operation happens in the code and SharePoint tries to protect unsafe updates to its list/ libraries.
To resolve the same error in such cases you need to put your code between the following code stub:

Now rebuild the solution and deploy and test again!

How to add ECB Menu Item for specific SharePoint List or Library

How to add ECB Menu Item for specific SharePoint List or Library

To add ECB Menu Item for specific SharePoint List or Library, first you need to know the Registration ID for that list. To get that, go to the desired List's Settings page and then select Advanced Settings. In that page, enable Management of Content Types and select OK. Now in the List settings page, go to the Content Type Section and select the Content Type listed there.

So in my case, when I selected Document content type, it took me to the next page and in the URL of the next page you have the 'ctype' listed at the end of the url:

Copy that CType as that is going to act as your Registration ID.
Next go to your Visual Studio solution and open Element.xml file. Change the RegistrationType's value to 'ContentType' and place the copied CType value to the 'RegistrationId's value field:

Now just save the file, and deploy the solution from visual studio if working in your development environment or else install and activate the feature to notice the custom ECB Menu only appearing in the specific list :)

How to deploy a WSP to a specific Web Application

How to deploy a WSP to a specific Web Application

Many time there will be requirement to deploy a custom solution to a specific Web Application. But at the time of deployment Power Shell starts throwing the following error:

Install-SPSolution : This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application. 
At D:\XXX\YYY\DeployWSP.ps1:2 char:19 + Install-SPSolution <<<<  -Identity CustomSPSolution.wsp -webApplication "http://testSPSite" -GACDeployment + CategoryInfo : InvalidData: (Microsoft.Share...InstallSolution: SPCmdletInstallSolution) [Install-SPSolution], SPException + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletInstallSolution

From the error message it is clear that SharePoint is looking for some resources specific to the web Application and could not find any. In many cases it is possible that your custom solution don't need any web application specific resources and in those cases we need to fool SharePoint thinking that the WSP has some Web Application specific resources. To do that open you Visual Studio solution and then double click on the Package folder present in the Solution Explorer. Once it is opened, select the Manifest tab and expand the 'Edit Option' present at the bottom of the page. In general Manifest Template going to have following text:

Inside the Solution node paste the following code stub:
Change highlighted sections as described and you will be good to deploy your WSP to a specific web application from the Power Shell command prompt.