Sunday, February 22, 2015

Create Crawled Property for Custom Column - SharePoint 2013


Create Site column "TestName" using following powershell script 
#Get site and web object
$site = Get-SPSite -Identity "http://MySiteurl"
$web = $site.RootWeb
#Assign fieldXML variable with XML string for site column
$fieldXML = '<Field Type="Text"
Name="TestName"
Description="This is a test date column."
DisplayName="Test Name"
StaticName="TestName"
Group="Test Custom Columns"
Hidden="FALSE"
Required="FALSE"
Sealed="FALSE"
ShowInDisplayForm="TRUE"
ShowInEditForm="TRUE"
ShowInListSettings="TRUE"
ShowInNewForm="TRUE"></Field>'
#Output XML to console
write-host $fieldXML
#Create site column from XML string
$web.Fields.AddFieldAsXml($fieldXML)
#Example of changing the site column settings after creation
#Configure Test Date column to be Date Only instead of Date & Time
$dtField = $web.Fields["Test Name"]
$dtField.Update()
#Dispose of Web and Site objects
$web.Dispose()
$site.Dispose()
Open  Search Service application  in central admin and run incremental crawl. 
Under Crawled properties search for "TestName"
If missing custom site columns in crawled properties, you should:
  1. verify your custom fields is in use (in existing item or at least associated with visible content type)
  2. check your search settings and crawled category properties
  3. do a Search Index Reset
  4. perform a full crawl
Even after full crawl if you can't find your column in crawled properties then create it using following powershell script.

add-pssnapin microsoft.sharepoint.powershell

$searchapp = Get-SPEnterpriseSearchServiceApplication

$cat = Get-SPEnterpriseSearchMetadataCategory -SearchApplication $searchapp -Identity SharePoint

$crawlprop = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Limit 1

New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Name "ows_TestName" -PropSet $crawlprop.PropSet -Category $crawlprop.CategoryName -IsNameEnum $false -VariantType $crawlprop.VariantType -IsMappedToContents $false

Now search again in crawled properties. you will find your "TestName" column.




Wednesday, February 18, 2015

Access is denied - SharePoint 2013 search crawl

Error Message : Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has “Full Read” permissions on the SharePoint Web Application being crawled. ( Error from SharePoint site: HttpStatusCode Unauthorized The request failed with HTTP status 401: Unauthorized. )

Context: Application 'Search Service Application', Catalog 'Portal_Content'

Details: Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled. (0x80041205)

Solution: Add Default Content Access Account for Search in your web application

Add-PSSnapin Microsoft.sharepoint.powershell
$userName = "<Domain\SearchAccount>" 
$displayName = "Search Crawl Account" 
Get-SPWebApplication https://mywebApplicationUrl | foreach { 
$webApp = $_ 
$policy = $webApp.Policies.Add($userName, $displayName
$policyRole = $webApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead) 
$policy.PolicyRoleBindings.Add($policyRole
$webApp.Update() 
}


It should fix the issue.


Tuesday, January 27, 2015

Hide Ribbon in SharePoint 2013


You might have thought to show Ribbon to administrator and hide it from other users due to security reason.


 In SharePoint 2013 , we can not modify the master page directly, we need to modify the concern html page.

Every master page in 2013 would have it concerned html page eg for Seattle.master we have Seattle.html
for oslo.master we have oslo.html page.

1. Open the html page in SharePointDesigner 2013.
2. Look for <div id=”ms-designer-ribbon”>
…..
</div>
3. Add the following markup enclosed in the <!--MS:--> and <!--ME:—> tags,
<!--MS:<SharePoint:SPSecurityTrimmedControl runat="server" PermissionsString="FullMask">-->
<div id=”ms-designer-ribbon”>
….
</div>
<!—MS:</SharePoint:SpSecurityTrimmedControl>—>
the design manager will create the corresponding master page with the correct functionality of showing the Ribbon for only administrators.

You can check different permissions level HERE.