Friday, January 31, 2014

"Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException", SharePoint exception after applying cumulative update\service pack

After applying a cumulative update on one of my SharePoint server, tried to run configuration file using psconfig.exe -cmd upgrade -inplace b2b -wait -force command, i got an error saying that "Exception: Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException: An upgrade conflict has occurred and you must re-try this action"

We can fix this exception by setting line-update-running property to true. To do that Open command prompt with administrator privileges and navigate to bin folder (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Bin) and execute following command

stsadm -o setproperty -pn command-line-upgrade-running -pv Yes

By running this command on SharePoint server, it will reset the command-line-upgrade-running property. We need to execute this command on all the SharePoint servers in the farm after upgrading. Once we are done with running this command, we have to run config command as

psconfig.exe -cmd upgrade -inplace b2b –wait –force

Wednesday, January 29, 2014

SharePoint search error “SharePoint item being crawled returned error when attempting to download the item”

While working with SharePoint, I got an error in search service when I try to index a page having search results using for roll the content in site collection. My search service application and content source are working fine. After checking this error in logs and digging in to this error I found that we have to change User agent value.
To do that,

Open Registry editor (Run -> regedit) and navigate to “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Global\Gathering Manager” key.



Change the value of “User Agent” from “MSIE 4.01” to “MSIS 8.0” and restart SharePoint search service.

Tuesday, January 28, 2014

Content Enrichment web service callout in SharePoint

In SharePoint 2013 search, as a developer we can add custom steps to process the content to modify the managed properties before indexing. We can do this by implementing custom web service in SharePoint to enrich the managed properties of the items that processed.

To configure the content enrichment functionality by using Power Shell commands. By Using Get-SPEnterpriseSearchContentEnrichmentConfiguration command we can get the content enrichment configuration for search service application. We can write the commands as

$searchServiceApp = Get-SPEnterpriseSearchServiceApplication
Get-SPEnterpriseSearchContentEnrichmentConfiguration –SearchApplication $searchServiceApp

To save the content enrichment configuarations to the search service application using Set-SPEnterpriseSearchContentEnrichmentConfiguration command. 

To add new content enrichment object using New-SPEnterpriseSearchContentEnrichmentConfiguration and to remove current content enrichment configuration from specific search service application using Remove-SPEnterpriseSearchContentEnrichmentConfiguaration command as shown below.

$config = New-SPEnterpriseSearchContentEnrichmentConfiguration

$searchServiceApp = Get-SPEnterpriseSearchServiceApplication
Remove-SPEnterpriseSearchContentEnrichmentConfiguration –SearchApplication $searchServiceApp

In next post I will write how to create a content enrichment web service and how to configure that service to SharePoint 2013. 

Monday, January 27, 2014

Hit counter for SharePoint site

Generally few of blog sites I have checked the hit counter to count the number of hits for that site. For my blog also we can see the hit counter on the right bottom showing like the image below.


So Is there any feature or anything is available in SharePoint. Yes we have same kind of feature in SharePoint to view number of hits for specific page. By default it is available in SharePoint 2007 as explained in the URL here.

SharePoint 2010 we don’t have that feature. But we have a WebPart available in codeplex to achieve this functionality. We can download the file from codeplex.

But before adding this WebPart to our site, we have to create custom list as Statistics with URL (Multiple lines of text), Date (Single line of text), and Username (Single line of text) fields and provide contribute permissions for visitors and viewers group. So that all the visits will be listed. Hope it will help.

Sunday, January 26, 2014

Code Access Security in SharePoint web parts

Installing SharePoint web part dll files in GAC can cause some security implications. By default all the web parts will be installed in the GAC with full trusts. We can install web parts in web application dedicated bin folder. Web parts in bin folder will run in partial trust and will have only limited access to the bin folder.

If web part needs additional permission levels, we need to create custom CAS policies with permissions. By adding custom policies we can make the code to run in full trust and all the code will run with full trust without depending on the location where it installed.

Code accessibility Security (CAS) is a policy that limits the access to an assembly, System resources and operations. By default SharePoint will have built-in policies from ASP.NET, it will use minimal set of permissions to protect the server and infrastructure from vulnerable code. If web part needs greater access will have minimal settings and there are number of  ways that we can increase the permissions of the web part by creating custom CAS policy and increasing the overall trust level for the server farm in the web.config.

We can have WSS_UserCode, WSS_Minimal, WSS_Medium Built-In security settings in SharePoint foundation inheriting from ASP.NET trust levels. By default this built-in SharePoint Foundation policy files located in %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\CONFIG directory named wss_usercode.config, wss_minimaltrust.config and wss_mediumtrust.config.

By default SharePoint foundation will have WSS_Minimal trust level. This will supports all the permissions in the ASP.NET minimal trust. WSS_Minimal policy will restrict accessing all the web parts from advanced operations.  WSS_Medium level allows accesing SharePoin object model and file operations. This will also allows to access to environment variables.
We can check security policies in web.config file as

<securityPolicy>
<trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_mediumtrust.config" />
<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_minimaltrust.config" />
</securityPolicy>

We can add custom files to SharePoint and add the tag to in Security policy tag as

<trustLevel name="WSS_Custom" policyFile="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\config\wss_custom_wss_minimaltrust.config" />