Tuesday, October 1, 2013

The SharePoint item being crawled returned an error when requesting data from the web service. (Error from SharePoint site: *** Index was outside the bounds of the array.)

We have below errors when we run the search crawl in the SharePoint 2010 farm.

1) The SharePoint item being crawled returned an error when requesting data from the web service. (Error from SharePoint site: *** Index was outside the bounds of the array.)
2) The object was not found.
3) The server is unavailable and could not be accessed. The server is probably disconnected from the network.
4) This item could not be crawled because the repository did not respond within the specified timeout period. Try to crawl the repository at a later time, or increase the timeout value on the Proxy and Timeout page in search administration. You might also want to crawl this repository during off-peak usage times.
5) The docfile has been corrupted
6) There is more than one match for your term. Please disambiguate which term you would like to use.
7) The SharePoint item being crawled returned an error when requesting data from the web service. ( Error from SharePoint site: *** Root element is missing. )

We have fixed all issues by following below steps which are recommended by Microsoft

1. Take a snapshot of SharePoint Servers and SQL servers.
2. Take back up of all the content databases.
3. Download OCT CU 2011 (http://support.microsoft.com/kb/2596505 )
4. Install this CU On SharePoint Server.
5. Run SharePoint Products & Configuration Wizard.
6. Once completed Run the full crawl.


Still if you see the errors you might have some problem with your managed metadata.



For example when you restore your SharePoint site to development environment from production, you should restore managed metadata service database as well. Then only metadata works fine and it will synchronize with SharePoint site database.

Update Managed Metadata service database (to fix invalid term set)

1) Take a backup of production managed metadata service database
2) Restore to your development server or where ever you are working
3) Go to central admin site, create a new managed metadata service or update existing metadata service database name field with your recently restored database name.
4) If you have created a new metadata service, you have to check the checkbox of that newly created service to the web application.


Central Administration>Application Management>Service Applications>Manage service applications
>select Managed Metadata Service> select Properties from ribbon

Update your “database name” (the one recently you have taken backup and restored from production) field as shown in screenshot



Monday, September 30, 2013

An exception occurred when trying to issue security token: Method is only supported if the user name parameter matches the user name in the current Windows Identity SharePoint 2010 FBA

You will see this error when you are using windowstokenroleprovider
<add applicationName="/" name="MyRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Change to sql role provider in your web.config file. check your central admin and

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\SecurityToken\web.config 
 files as well.



<add connectionStringName="SQLConnectionString" applicationName="/" description="Stores and retrieves roles from SQL Server" name="MyRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

Wednesday, August 21, 2013

Query SharePoint Choice Field List Items using CAML

Below script gets list items where 'Address Type' not equal to ‘Home Address’ of choice field

Start-SPAssignment
-Global
$url = "YoursiteURL"
$web = get-spweb $url

$list=$web.Lists["EmployeeDocuments"]
Write-Host $list.title
$i=1

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery ="<Where><Neq><FieldRef Name='Address_x0020_Type'/><Value Type='Choice'>Home Address</Value></Neq></Where>"
$spQuery.Query = $camlQuery
$spQuery.ViewAttributes = "Scope=Recursive";
$spListItems = $list.GetItems($spQuery)
     
Write-Host "count" $spListItems.count
     
#    foreach ($item in $spListItems)
#           {
#                 write-host $i  $item["Address Type"]
#                
#                 $i++
#           }


 Stop-SPAssignment -Global



Friday, August 16, 2013

Create SharePoint Choice Field (Site Column) using PowerShell

Start-SPAssignment -Global
$url = "siteurl"
$web = get-spweb $url

$fieldName = "Surya"
$field = $web.Fields[$fieldName]

 if($field -ne $nul)
 {
      Write-Host $field.Title "Field already avilable in the site"
 }
 else
 {

#There are 2 ways to create a field.
#First Apporach
 <#
      Write-Host "no fields exist with this name. creating..."
      $web.fields.add($fieldName, "Choice", $true)
      $field = $web.fields.getfield($fieldName)
      $field.Group = "Custom Columns"
      $field.Choices.Add("Yes")
      $field.Choices.Add("No")
      $field.Update()
     Write-Host "Field Created"
#>

#Second Apporach

      $suryafield = "<Field Type='Choice' DisplayName='Surya' Required='TRUE' Format='Dropdown' Group='Custom Columns'
      FillInChoice='FALSE' StaticName='Surya' Name='Surya'>
            <CHOICES>
                <CHOICE>YES</CHOICE>
                <CHOICE>NO</CHOICE>
            </CHOICES>
           </Field>"
      $web.Fields.AddFieldAsXml($suryafield)
  Write-Host "Field Created"
 }

 Stop-SPAssignment -Global


Wednesday, August 14, 2013

Create Content Types and Fields using Powershell

 Below script will work for

1.       1. Add Content Types to the web site
a.       Create a Content Type
b.      Add fields to Content Type
c.       Modify existing fields of  Content Type
d.      Delete fields from Content Type
e.      Create a new field and then add to the content type
2.       2. Add Content Type to the SharePoint List
3.       3. Sorting Content Types in the List

I referred below posts



Start-SPAssignment -Global

function  Sort-ContentTypes(
       [Microsoft.SharePoint.SPList]$list) {

         Write-Host $list.Title
$rootFolder = $list.RootFolder
$DefaultContentTypeName = "Document"  #setting "Document" as default content type.

 $rootFolder.UniqueContentTypeOrder = $null
 $rootFolder.Update()

#Get content types fromt the button
$contentTypesInPlace = New-Object 'System.Collections.Generic.List[Microsoft.SharePoint.SPContentType]'
$contentTypesInPlace = $rootFolder.ContentTypeOrder
 
#Has a default content type name been specified?
      if ($DefaultContentTypeName)
      {
            $contentType = $contentTypesInPlace | where { $_.Name -eq $DefaultContentTypeName }
            if ($contentType -ne $null)
            {
                  #Add the default content type
                  $sortedListOfContentTypes = New-Object 'System.Collections.Generic.List[Microsoft.SharePoint.SPContentType]'
                  $sortedListOfContentTypes += $list.ContentTypes[$DefaultContentTypeName]
                   
                  #Remove the default content type from the list
                  $contentTypesInPlace = $contentTypesInPlace | where {$_.Name -ne $DefaultContentTypeName}
            }
            else
            {
                  Write-Error "$DefaultContentTypeName was not found in the list, sorting by Name alone"
            }
      }
      else
      {
            Write-host "No default content type specified"
      }
       
      #sort the remaining content types and add the sorted list
      foreach ($contentType in $($contentTypesInPlace | Sort-Object -Property Name ))
      {
      #Add the content types
            $sortedListOfContentTypes = [Microsoft.SharePoint.SPContentType[]] $sortedListOfContentTypes + $contentType
      }

      $rootFolder.UniqueContentTypeOrder = [Microsoft.SharePoint.SPContentType[]] $sortedListOfContentTypes
       
      #Update the root folder
      $rootFolder.Update()
      Write-host "ContentType(s) sorted and added to the dropdownlist in list $($list.Name)"
     
 }



$url = "http://spdev5:8002/sites/library"
$web = get-spweb $url

#The Display Name of the Content Type
$ctypeName = "SuryaCT1"

try{

if($web.availablecontenttypes[$ctypeName] -eq $null)
{
      $ctypeParent = $web.availablecontenttypes["Document"]
      $ctypeTest = new-object Microsoft.SharePoint.SPContentType($ctypeParent, $web.contenttypes, $ctypeName)
      ##group name
      $ctypeTest.Group = "Custom Group"
      $web.contenttypes.add($ctypeTest)
     
#     $ctypeTest = $web.ContentTypes[$ctypeName]
     
      Write-Host "ctypeAgenda" $ctypeTest.id
     
      ##Add fields to the ContentType

      $field = $web.fields.getfield("Field1")
     
      if($ctypeTest.Fields["Field1"] -eq $null)
      {
            $fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
            $ctypeTest.fieldlinks.add($fieldLink)
      }
     
      ##Update existing fields - as Required
      if($ctypeTest.Fields["Field2"] -ne $null)
      {
            $field = $ctypeTest.Fields["Field2"]
            $ctypeTest.FieldLinks[$field.Id].Required=$true
      }
       
     
      ##Delete fields from  ContentType
           
      if($ctypeTest.Fields["Field3"] -ne $null)
      {
         Write-Host "Field2"
        $field = $ctypeTest.Fields["Field3"]
        $fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
        $ctypeTest.FieldLinks.Delete($fieldLink.id);
      }
     
      ##create new field and then add to the ContentType
       
      $web.fields.add("SuryaField", "Text", $false)
      $field = $web.fields.getfield("SuryaField")
      $field.Group = "Custom Columns"
      $fieldLink = new-object Microsoft.SharePoint.SPFieldLink($field)
      $ctypeTest.fieldlinks.add($fieldLink)


      $ctypeTest.Update($true)
       
}
else
{
      Write-Host $ctypeTest " Contentype is already avilable in the site."
}

#$ctypeTest = $web.ContentTypes[$ctypeName]
## Add ContentType to the SharePoint List
      if($ctypeTest -ne $null)
            {
           
            $list =  $web.Lists.TryGetList("suryadocs")
           
            if($list.ContentTypesEnabled -eq $false   )
            {
            $list.ContentTypesEnabled = $true;
                  $list.Update()
            }
             
              if ($list.ContentTypes[$ctypeTest.Name] -eq $null)
             {
               $list.ContentTypes.Add($ctypeTest);
                   Write-Host $ctypeTest.name " ContentType added"
                   Sort-ContentTypes $list
             }
            }
}
catch
{
      Write-Host "Error occurred while Updating:"  $_  -ForegroundColor Red
}

Stop-SPAssignment –Global



Followers