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" />

Tuesday, January 21, 2014

Configure object cache settings in SharePoint

Object cache settings can be configured in Site Collection level from SharePoint user interface. We can configure the maximum cache size in we application level on the front-end web server by placing restrictions on maximum amount of memory to all site collection cache. We can configure Object cache settings for a web application in front-end web server by using the steps below,

Navigate to IIS Manager Select the web application. Right click on the web application, Click on Explore. We can see Windows Explorer with directories


Select web.config file and open the file in any editor tool. Check for <ObjectCache tag, to change the size of the cache modifies maxSize from 100MB to required value. Save and update the file.


Thursday, January 16, 2014

Configure SharePoint 2013 document center Connection

We can use connection path to send documents to a document center or record center in SharePoint 2013. This connection will specify the web application that documents will sent from and document center or record center that to be sent to.

As a farm admin we can create the connections to copy or move the content. To create the connections we have to follow the steps below,
Navigate to SharePoint central administration General Application settings and click on “Configure Send To Connections” link in “External Service Connections” section.



In Configure Send To Connections page, Select the web application field that hosts the documents to sent. In Tenant Settings section, check “Allow sites to send to connections outside their tenancy” check box to allow tenants in to send content to other tenants.
Select “New Connection” in Send To Connections list











Enter Display Name field for the connection name, Send to URL filed to enter the URL to the content organizer for the destination site. Click on Click here to test link to test the connection. To display the connection in list Select “Allow manual submission from the Send To menu”.


In “Send To action” dropdown list, We have three options, Copy, Move, Move and Leave a Link. Select Copy to copy the document and send to destination. Select Move to delete the document in current location after copying. Select Move and Leave a link to delete the document from current location and add a link on current location referring to the document. We have to specify the information in expansion dialog box for audit logging when user sends this document by using current connection. Click on Add Connection button to create the connection.


Wednesday, January 15, 2014

Create SharePoint 2013 custom search engine in Chrome

We can add search center for SharePoint site in google chrome as regular google search for SharePoint site. Here we are just creating a custom search engine by passing SharePoint search site Url as shown below.

Navigate to google chrome and right click on the address bar, Select “Edit search engines” option



In “Search Engine” dialog box, other search engine division we have to fill Search Engine Name, Keyword, Url. Google chrome will use default site domain name . In keyword section enter SharePoint Search for easy understanding. In URL, enter the search URL and assign “%S” at the end. Click on Done button to save the search engine settings.




To search the details, write, “SharePointSearch” in browser address bar and press tab to enter the search query. Here I am entering Suresh and result will display as the images.

















Thursday, January 9, 2014

Creating content sources in SharePoint using PowerShell commands

We can create the content sources based on the content types as per the requirements. Content types for content sources might be SharePoint site or web or Files that associated with in SharePoint environment.
To create a content source based on a web content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName;
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa);
if($myType -eq “Web”){

$webContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.WebContentSource], $contentSourceName);

$webContentSource.startAddresses.Add($siteUrl);
}

Here $myType is content type

To create a content source based on a SharePoint content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
if($myType -eq “SharePoint”){

$sharepointContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName);

$sharepointContentSource.startAddresses.Add($siteUrl);
}

To create a content source based on a File content type we can use the following script,

$contentSourceName = “Name of the content source to be configured”;
$siteUrl = “URL of the Site”;
$ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$ssaContent = new-object Microsoft.Office.Server.Search.Administration.Content($ssa)
if($myType -eq “File”){

$fileContentSource=$ssaContent.ContentSources.Create([Microsoft.Office.Server.Search.Administration.SharePointContentSource], $contentSourceName);

$fileContentSource.startAddresses.Add($siteUrl);
}

Monday, January 6, 2014

Create custom profile property in SharePoint user profile programmatically

While working on user profile service I got the requirement to create custom property through coding for one of my client. I have found the solution to create custom property from Ahmedmandany blog. To create the property, we have to get the current service context  by passing the site object. From the service context object create new UserProfileConfigManager object. By using UserProfileConfiguaration object we can get the CoreProperties in the service as shown the code below.

SPServiceContext currentServiceContext = SPServiceContext.GetContext(SiteCollection);
    
//Here SiteCollection is SPSite object for current site

UserProfileConfigManager userProfileConfigManager = new UserProfileConfigManager(currentServiceContext);

CorePropertyManager usreProfileCoreProperties = userProfileConfigManager.ProfilePropertyManager.GetCoreProperties();

Create profileProperty list and with string type objects. Insert data into the list as shown below,

List<string> myCustomProperties = new List<string>();
myCustomProperties.Add("My Custom Property");

We can get the ProfilePropertyManager object from ProfileConfigManager. 

ProfilePropertyManager propertyManager = profileConfigManager.ProfilePropertyManager;

Check the property is exits or not in CoreProperties. If not exists, add property to the core properties. Add PropertyInstance, ProfileTypeProperty and ProfileSubtypePropertyManager objects, update all the properties as per the requirements.

CoreProperty coreProperty = coreProperties.Create(false);
coreProperty.Name = profileProperty.Replace(" ", string.Empty);
coreProperty.Type = PropertyDataType.String;
coreProperty.Length = 4000;
coreProperty.DisplayName = "My Custom Property";
coreProperty.Description = "My Custom Property" ;
coreProperty.IsAlias=false;
coreProperty.Commit();
      
ProfileTypePropertyManager profileTypePropertyManager = propertyManager.GetProfileTypeProperties(ProfileType.User);
ProfileTypeProperty profileTypeProperty = profileTypePropertyManager.Create(coreProperty);
profileTypeProperty.IsVisibleOnViewer =true;
profileTypeProperty.IsVisibleOnEditor = true;
profileTypePropertyManager.Add(profileTypeProperty);
    

ProfileSubtypeManager profileSubTypeManager = ProfileSubtypeManager.Get(currentServiceContext);
ProfileSubtype profileSubtype = profileSubTypeManager.GetProfileSubtype               (ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
ProfileSubtypePropertyManager profileSubtypePropertyManager = profileSubtype.Properties;


ProfileSubtypeProperty profileSubtypeProperty = profileSubtypePropertyManager.Create(profileTypeProperty);
profileSubtypeProperty.IsUserEditable = true;
profileSubtypePropertyManager.Add(profileSubtypeProperty);

Thursday, January 2, 2014

Print to PDF option for SharePoint 2013 documents

From SharePoint 2013 by adding OWA we can get many add-ons. Few of them are Document previewing documents on hover and print PDF etc. Document preview allows users to view the documents and read entire document.

Print PDF will allow users to print the document as in PDF. We can locate the menu and select the option to print PDF.

To locate print PDF option, navigate to library or the WebPart where we are storing the documents. Select the document and click on “…” to the right side of the document. Click on menu on the bottom right.


We have the options to download a copy and Print PDF as shown below. Select “Print to PDF” option to print document as PDF.


We can see the window with link in the office web app. Click on the link to view the pdf.



We can cancel the printing options depending on the access additional options like download or zoom. We can see this option by adding OWA features to SharePoint.