Pages

Search This Blog

Thursday, June 26, 2014

Issue with refiners in SharePoint 2013 with Search REST API and Anonymous access

If you ever worked on developing a Search portal using SharePoint native REST API, you might have ended up on issue with search Refiners not being returned for Anonymous users. Although for enabling search for anonymous users, you would need to explicitly set the "Safe for anonymous" setting on a managed property to true however there is one more setting that needs to be added in the whitelist of the queryparametertemplate file. 

In the whitelist tag, add following entry for refiners:
<a:string>Refiners</a:string>
So the whole Whitelist will look like:
<WhiteList xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        <a:string>RowLimit</a:string>
        <a:string>SortList</a:string>
        <a:string>StartRow</a:string>
        <a:string>Refiners</a:string>
        <a:string>RefinementFilters</a:string>
        <a:string>Culture</a:string>
        <a:string>RankingModelId</a:string>
        <a:string>TrimDuplicatesIncludeId</a:string>
        <a:string>ReorderingRules</a:string>
        <a:string>EnableQueryRules</a:string>
        <a:string>HiddenConstraints</a:string>
        <a:string>QueryText</a:string>
        <a:string>QueryTemplate</a:string>
    </WhiteList>

Friday, April 4, 2014

spweb.properties.remove not working (SPPropertyBag)


This might have bugged a lot of developers that spweb property bag doesn't removes the key when you execute following code

if ( spweb.Properties.ContainsKey(key) )
{
    spweb.Properties.Remove(key);
    spweb.Properties.Update();
}

The Correct code for making sure that property is removed from the from the spweb properties bag is : -

if ( spweb.Properties.ContainsKey(key) )
{
    spweb.AllProperties.Remove(key);
    spweb.Properties[key] = null;
    spweb.Properties.Update();
    spweb.Update();
}

Saturday, March 29, 2014

Authentication issue from SharePoint Server using FQDN




If you are using a fully qualified domain name for your sharepoint site which is hosted on port 80 using domain or subdomain then you might not be able to access that site from the server itself. If you try to open the site then it will keep you prompting for user credentials again and again.
Now for that matter the problem lies in the resolution part of the domain name so you have to make any entry in backcoonectionhostnames to resolve the name to the local machine itself. 
You need to run this powershell command in your server which will make an entry in your registry and you will be good to go after that :-
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa\MSV1_0 -Name "BackConnectionHostNames" -Value "<your domain or subdomain name without http or https>" -PropertyType multistring

To update this property in future in case you have added some more domain names

Set-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa\MSV1_0 -Name "BackConnectionHostNames" -Value "<first domain or subdomain name>","<second domain or subdomain name>"

if you want to know the existing domain names in this property then retrieve by following command

Get-ItemProperty -Path HKLM:\System\CurrentControlSet\Control\Lsa\MSV1_0 

Do an IISRESET or application pool recycle to make apply these changes.

Thursday, March 13, 2014

SharePoint 2013 SP1 Launched

Long awaited SharePoint 2013 SP1 (Service Pack 1) is available for download:-

Here are the links :-

Microsoft SharePoint Foundation 2013 Service Pack 1 (SP1)


http://support.microsoft.com/kb/2817439

Microsoft SharePoint Server 2013 Service Pack 1 (SP1)


http://support.microsoft.com/kb/2817429


Tuesday, February 11, 2014

Install Timer Jobs through Powershell in SharePoint

If you need to install Timer service through Powershell in SharePoint, you can make use of the below script. This script will install custom timer job in the defined web application. Fir the purpose of testing, this script also has a function to execute the timer job. This is very helpful if you wish to execute your job immediately after installing.

Copy below code and paste it in file with extension - .ps1




#__________________________Install SharePoint Timer Jobs___________________________________

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#                             VARIABLE DECLATRATION
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#

# Grab the web app URL from User
write-host "Enter the Web Application Url where you want to deploy the Timer service:"
[string]$webAppUrl = Read-Host

# Define here the Timer Job assembly name.
[string]$assemblyName = "TechPerspect.TimerJobs"

# Define here the Job Name
[string]$jobName = "TechPerspect Demo Timer Job"

# Define the class name here. (assembly name + class name of timer job)
$className = "TechPerspect.TimerJobs.DemoTimerJob"


# load the required assemblies
[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][reflection.assembly]::LoadwithPartialName("Microsoft.Office.Server")

# Stop further execution of an error occured anywhere in script
$ErrorActionPreference = "Stop"


#
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#                                 Functions
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#

# This methods restarts SharePoint Timer service (OWSTIMER)
function global:Restart-TimerServices
{
    # Restart timer services
    Write-Host "Restarting SharePoint Timer services"
    Stop-Service "SPTimerV4"
    Start-Service "SPTimerV4"
}

function global:Install-TimerJob
{
    Restart-TimerServices

    # Load job assembly
    [void][reflection.assembly]::LoadwithPartialName($assemblyName)
    # below call is commented however may be used in Powershell v3.0, since          
    # LoadwithPartialName is depreciated after powershell 2.0
    #[System.Reflection.Assembly]::Load("TechPerspect.TimerJobs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d8668901f3456325")

    $objSPSite = [Microsoft.SharePoint.SPSite]$webAppUrl
    $objWebApplication = $objSPSite.WebApplication
    # search for the Job
    $objTimerJobInstance = $objWebApplication.JobDefinitions | ? { $_.Name -like $jobName }

       # Delete the job instance if already exists
       if ($objTimerJobInstance)
    {
        Write-Host "Job [" $objTimerJobInstance.Name "] already exists. Deleting..."
       $objTimerJobInstance.Delete()
       }
      
       # Initlize new instance of timer job
    # Note that the argument List should be same, which you have defined in your 
    # timer service code for invoking the service.
    # Argument list could contain 1, 2, 3 params depending upon constructor used 
    # in your timer code
    $objTimerJobInstance = new-object $className -ArgumentList $jobName,$objWebApplication
      
       # Create a Daily Schedule
    $sched = new-object Microsoft.SharePoint.SPDailySchedule
    # setting the hour to execute at 0100 AM to 0200 AM
    $sched.BeginHour = 1
    $sched.EndHour = 2
    $objTimerJobInstance.Schedule = $sched
    $objTimerJobInstance.Update()

       # Set the schedule to the timerjob object and save the job schedule
    $objTimerJobInstance.Schedule = $sched
    $objTimerJobInstance.Update()
   
    # Dispose site
    $objSPSite.Dispose()

    Restart-TimerServices
}



#This method will execute the Timer Job.(helpful when testing the timer jobs)
function global:Execute-TimerJob
{


    # Open site
    $objSPSite = [Microsoft.SharePoint.SPSite]$webAppUrl
    $objWebApplication = $objSPSite.WebApplication

    # Content DB to execute job on
    $contentDB = $objWebApplication.ContentDatabases[0]

    # Search for the Job
    $objTimerJobInstance = $objWebApplication.JobDefinitions | ? { $_.Name -like $jobName }

    if ($objTimerJobInstance)
    {
        Write-Host "Executing Timer Job [" $objTimerJobInstance.Name "]..."
        $objTimerJobInstance.Execute($contentDB.Id)
        Write-Host "Job Executed successfully!"
    }
    else
    {
        Write-Host "Job [" $jobName "] not found"
    }
    # Dispose site
    $objSPSite.Dispose()
}



#
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#                                        MAIN
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#


Install-TimerJob

# If you want to test the timer service, uncomment the below method call
#Write-Host "Executing the Timer Job..."
#Execute-TimerJob


Friday, February 7, 2014

SharePoint 2010 : Custom BCS connector for Search with Security Trimming, Batching, Incremental Crawling



This guide is designed to highlight the solution for enabling security trimming on search results in SharePoint 2010 for external database. It also focuses on large datasets and file system crawling. It provides an overview of the requirement, a solution for the same, and concludes with implementation of the solution suggested. In order to have item level security implemented and search result trimming based on security, we need to have the security descriptor generated for each record and present in the table for each row. BCS is used to pull data and index in SharePoint for implementing search driven applications, we need constant updation of data from the external system. In such systems we need incremental update to work to ensure CRUD operations. If you have documents stored in your External Systems then it is possible using the Business Connectivity Services (BCS) give your end users the ability to access and crawl these artifacts with ease. The Stream Accessor method allows you to pull System.Byte[] data from your External System and make it available from within SharePoint.



Sunday, January 5, 2014

All users are logged in as System Account

There is a very strange problem we were facing in which any contributor or user when logged in into SharePoint 2010 site then it started showing him / her as sharepoint\system account. This is very strange and we checked all the possible scenarios to confirm that nothing applies in my case :- 


Checked the user policy in central admin and there was nothing that was causing this issue





















Another possibility was to check if the farm admin account is operating as system account but that was also not the case.






Now another question came in my mind if this setting is not enabled then why does SharePoint showing system account at all. Strange but true. May be this setting is not at all applied on the farm account any by default it consider it as system account.



Then we checked the farm account is not set to the contributors ad account but it was correct and set to the farm admin account only





Then we checked if there is any problem with IIS pool Account and it was correctly set except that if was running as a specific user which is my farm admin account. Now I got the issue, this is the reason why all my users were being impersonated as system account. I changed it to Application user (pass-through authentication) and it solved the mystery. 






All my users are happy now as they can see their names as logged in user and and that makes me feel happy as well. It also solved lot of issues related to the authentication and access denied errors as and when user tries to perform any activity on which it doesn't has access by SharePoint.




Friday, January 3, 2014

How to programmatically update a content source in SharePoint 2010 enterprise / fast search

Following are the assembly references required to execute the code


using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.BusinessData.Administration;
using Microsoft.SharePoint.BusinessData.Parser;
using Microsoft.SharePoint.BusinessData.SharedService;
using Microsoft.SharePoint.BusinessData.Infrastructure;
using Microsoft.BusinessData.Infrastructure;
using Microsoft.BusinessData.MetadataModel;
using Microsoft.Office.Server.Search;
using Microsoft.SharePoint.Search.Extended.Administration;
 
Here is the function that take two parameters as first is your central application url and other parameter to define if you want to configure fast search or enterprise search. You can use the code individually also in case you dont want to configure both.


public void UpdateContentSource(string WebAppUrl, bool IsFast)
        {
            try
            {

                string strContentSourceName = "<CustomContentSourceName>";
                string strLogSystemName = "<BDCLogSystemName>";
                //Content Source Update Started
                //execute this code if you are updaameting a fast search content source. else user for enterprise content source
                if (IsFast)
                {
                    foreach (SearchServiceApplication FASTServiceApp in SearchService.Service.SearchApplications)
                    {
                        SearchServiceApplicationType at = FASTServiceApp.SearchApplicationType;
                        if (FASTServiceApp.SearchApplicationType == SearchServiceApplicationType.ExtendedConnector)
                        {
                            Content FastContent = new Content(FASTServiceApp);
                            bool CheckExist = false;
                            ContentSourceCollection FastCSColl = FastContent.ContentSources;
                            foreach (ContentSource cs in FastCSColl)
                            {
                                if (cs.Name.Equals(strContentSourceName))
                                {
                                    CheckExist = true;
                                    Console.WriteLine(strContentSourceName + " FAST Search Content Source already exist");

                                }
                            }
                            BusinessDataContentSource CustomConSource = null;
                            if (CheckExist)
                            {
                                CustomConSource = (BusinessDataContentSource)FastCSColl[strContentSourceName];
                                if (CustomConSource.StartAddresses.Count > 0)
                                {
                                    CustomConSource.StartAddresses.Remove(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                                }
                                CustomConSource.Delete();
                                FastCSColl.Update();
                                Console.WriteLine(strContentSourceName + " FAST Search Content Source Deleted");
                            }

                            CustomConSource = (BusinessDataContentSource)FastCSColl.Create(typeof(BusinessDataContentSource), strContentSourceName);
                            CustomConSource.StartAddresses.Add(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                            CustomConSource.CrawlPriority = CrawlPriority.Normal;
                            FastCSColl.Update();
                            Console.WriteLine("External Source FAST Content Source Created");

                        }

                    }
                }
                else
                {
                    using (SPSite site = new SPSite(WebAppUrl))
                    {
                        foreach (SearchServiceApplication objServiceApp in SearchService.Service.SearchApplications)
                        {
                            if (objServiceApp.SearchApplicationType == SearchServiceApplicationType.Regular)
                            {
                                SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site));
                                Guid appId = proxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;
                                SearchServiceApplication SearchApp = objServiceApp;         //SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(appId);
                                Content content = new Content(SearchApp);
                                ContentSourceCollection csColl = content.ContentSources;
                                bool CheckExist = false;
                                foreach (ContentSource cs in csColl)
                                {
                                    if (cs.Name.Equals(strContentSourceName))
                                    {
                                        CheckExist = true;
                                        Console.WriteLine(strContentSourceName + " is already exist");
                                    }
                                }
                                BusinessDataContentSource CustomConSource = null;
                                if (CheckExist)
                                {
                                    CustomConSource = (BusinessDataContentSource)csColl[strContentSourceName];
                                    if (CustomConSource.StartAddresses.Count > 0)
                                    {
                                        CustomConSource.StartAddresses.Remove(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                                    }
                                    CustomConSource.Delete();
                                    csColl.Update();
                                    Console.WriteLine(strContentSourceName + " Deleted");
                                }
                                CustomConSource = (BusinessDataContentSource)csColl.Create(typeof(BusinessDataContentSource), strContentSourceName);
                                CustomConSource.StartAddresses.Add(BusinessDataContentSource.ConstructStartAddress("Default", new Guid("00000000-0000-0000-0000-000000000000"), strLogSystemName, strLogSystemName));
                                CustomConSource.CrawlPriority = CrawlPriority.Normal;
                                csColl.Update();
                                Console.WriteLine("External Source Content Source Created");
                            }
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:" + ex.Message);
            }
            Console.WriteLine("Content Source Update Ended");

        }