Sunday, September 28, 2014

Configure Crawl Sources in sharepoint 2013

How to start a full crawl in Central Administration
Before you can start a full crawl in Central Administration, you have to specify which content source should be crawled. When you run a full crawl, all content in the content source is crawled even if that content has already been added to the search index.
For this scenario, we'll crawl the Local SharePoint sites content source.
  1. Go to Central Administration --> Manage service applications --> Search Service Application -- > Content Sources.
  2. On the Manage Content Sources page, hover over the Local SharePoint sites content source, and select Start Full Crawl from the menu.

The status of the crawl is shown in the Status column.
  1. Refresh this page until you see that the value in the Status column is Idle.
    This means that the crawl has finished.

  1. Optionally, you can verify that your items have been added to the search index by clicking Crawl Log.
    In our scenario, we now have 870 items in the search index, which is approximately the same amount of products we have in the Products list.

How to enable continuous crawls in Central Administration
You can only start a full crawl manually. Nobody wants the hassle of having to manually start a crawl every time a change is made to their catalog content, as this is neither an efficient nor practical way to work. So, to avoid this overhead, you can simply enable a continuous crawl of your content source that contains the catalog.
Continuous crawls start automatically at set intervals. Any changes that have been made to the catalog since the previous crawl, are picked up by the crawler and added to the search index.
To enable continuous crawls:
  1. Go to Central Administration --> Manage service applications --> Search Service Application --> Content Sources.
  2. On the Manage Content Sources page, click Your content source for which you want to enable continuous crawl, in our scenario case, this is Local SharePoint sites.
  3. Select the option Enable Continuous Crawls.

How to set continuous crawl interval
The default interval for continuous crawls is 15 minutes. You can set shorter intervals by using PowerShell. The code snippet below sets the continuous crawl interval to 1 minute.
$ssa = Get-SPEnterpriseSearchServiceApplication
$ssa.SetProperty("ContinuousCrawlInterval", 1)
So, by enabling continuous crawls, you can avoid a lot of frustration from content managers as they no longer have to wait for Search service application administrators to start a crawl for them. However, for some catalog changes, for example, enabling managed properties as refiners, continuous crawls are not sufficient, and you will need to do a full reindexing of the catalog content. But not to worry. Content managers have no reason for concern, because there is a way for them to initiate a full reindexing of the catalog.
How to initiate a reindexing of the catalog
To mark a catalog for reindexing, here's what to do:
  1. On your catalog (in our case the Products list in the Product Catalog Site Collection), click the LIST tab --> List Settings --> Advanced Settings.
  2. On the Advanced Settings page, click Reindex List.

How to view crawl status and schedule for a catalog
You can view the crawl status and schedule for an individual catalog. To do this:
  1. On your catalog (in our case the Products list in the Product Catalog Site Collection), click the LIST tab --> List Settings --> Catalog Settings.
  2. On the Catalog Settings page, you can see when the catalog was last crawled, and what crawls are scheduled to run when.
    In our case, we can see that the catalog was last crawled on 3/4/2013 at 5:30:17 AM, and that continuous crawls are scheduled to run every 15 minutes.

So, all in all, content managers can be happy because their content is added to the search index at short intervals, and Search service application administrators can be happy because they are no longer bothered by content managers constantly asking them to start a crawl.

Upgrading the web.config file to SharePoint 2013

In SharePoint 2010 if we have any of the custom CAS policy defined and which is also referred in web.config file, then on upgrading the site from 2010 to SharePoint 2013, that entry will be missing in the web.config file.

<TrustLevel node is not available in web.config by default in SP2013, we need to update the code to insert the additional node before adding the custom CAS policy.

Powershelll scripts for Feature activation

Enable-SPFeature -identity "<Feature ID>" -URL http://sharepointsite

Configure Crawl Rules in Sharepoint 2013

To create or edit a crawl rule
      1. Verify that the user account that is performing this procedure is an administrator for the Search service application.
      2. In Central Administration, in the Application Management section, click Manage Service Applications.
      3. On the Manage Service Applications page, in the list of service applications, click the Search service application.
      4. On the Search Administration page, in the Crawling section, click Crawl Rules. The Manage Crawl Rules page appears.
      5. To create a new crawl rule, click New Crawl Rule. To edit an existing crawl rule, in the list of crawl rules, point to the name of the crawl rule that you want to edit, click the arrow that appears, and then click Edit.
      6. On the Add Crawl Rule page, in the Path section:
  •       In the Path box, type the path to which the crawl rule will apply. You can use standard wildcard characters in the path.
  •        To use regular expressions instead of wildcard characters, select Use regular expression syntax for matching this rule.
7. In the Crawl Configuration section, select one of the following options:
     
      I.  Exclude all items in this path. Select this option if you want to exclude all items in the specified path from crawls. If you select this option, you can refine the exclusion by selecting the following:

Exclude complex URLs (URLs that contain question marks
Select this option if you want to exclude URLs that contain parameters that use the   question mark (?) notation.

      II. Include all items in this path. Select this option if you want all items in the path to be crawled. If you select this option, you can further refine the inclusion by selecting any combination of the following:

Follow links on the URL without crawling the URL itself. Select this option if you want to crawl links contained within the URL, but not the starting URL itself.

Crawl complex URLs (URLs that contain a question mark (?)). Select this option if you want to crawl URLs that contain parameters that use the question mark (?) notation.

Crawl SharePoint content as http pages. Normally, SharePoint sites are crawled by using a special protocol. Select this option if you want SharePoint sites to be crawled as HTTP pages instead. When the content is crawled by using the HTTP protocol, item permissions are not stored.

      8. In the Specify Authentication section, perform one of the following actions:

  •     To use the default content access account, select Use the default content access account.
  •     If you want to use a different account, select Specify a different content access account and then perform the following actions:
1.  In the Account box, type the user account name that can access the paths that are defined in this crawl rule.
2.  In the Password and Confirm Password boxes, type the password for this user account.
3.  To prevent basic authentication from being used, select the Do not allow Basic Authentication check box. The server attempts to use NTLM authentication. If NTLM authentication fails, the server attempts to use basic authentication unless the Do not allow Basic Authentication check box is selected.

  •     To use a client certificate for authentication, select Specify client certificate, expand the Certificate menu, and then select a certificate.
  •     To use form credentials for authentication, select Specify form credentials, type the form URL (the location of the page that accepts credentials information) in the Form URL box, and then click Enter Credentials. When the logon prompt from the remote server opens in a new window, type the form credentials with which you want to log on. You are prompted if the logon was successful. If the logon was successful, the credentials that are required for authentication are stored on the remote site.
  •     To use cookies, select Use cookie for crawling, and then select either of the following options:
1.  Obtain cookie from a URL. Select this option to obtain a cookie from a website or server.
2.  Specify cookie for crawling. Select this option to import a cookie from your local file system or a file share. You can optionally specify error pages in the Error pages (semi-colon delimited) box.

  •     To allow anonymous access, select Anonymous access.
              Click OK.

To test a crawl rule on a URL
1.      Verify that the user account that is performing this procedure is an administrator for the Search service application.
2.      In Central Administration, in the Application Management section, click Manage Service Applications.
3.      On the Manage Service Applications page, in the list of service applications, click the Search service application.
4.      On the Search Administration page, in the Crawling section, click Crawl Rules.
5.      On the Manage Crawl Rules page, in the Type a URL and click test to find out if it matches a rule box, type the URL that you want to test.
6.      Click Test. The result of the test appears below the Type a URL and click test to find out if it matches a rule box.

To delete a crawl rule
1.      Verify that the user account that is performing this procedure is an administrator for the Search service application.
2.      In Central Administration, in the Application Management section, click Manage Service Applications.
3.      On the Manage Service Applications page, in the list of service applications, click the Search service application.
4.      On the Search Administration page, in the Crawling section, click Crawl Rules.
5.      On the Manage Crawl Rules page, in the list of crawl rules, point to the name of the crawl rule that you want to delete, click the arrow that appears, and then click Delete.
6.      Click OK to confirm that you want to delete this crawl rule.

To reorder crawl rules
1.      Verify that the user account that is performing this procedure is an administrator for the Search service application.
2.      In Central Administration, in the Application Management section, click Manage Service Applications.
3.      On the Manage Service Applications page, in the list of service applications, click the Search service application.
4.      On the Search Administration page, in the Crawling section, click Crawl Rules.

5.      On the Manage Crawl Rules page, in the list of crawl rules, in the Order column, specify the crawl rule position that you want the rule to occupy. Other values shift accordingly.

Configure Best Bets in SharePoint


SharePoint 2013 Preview transforms all your old Search Keywords or Best Bets  into Query Rules .

So let’s create a Query Rule that fires on the exact query ‘image library’ or ‘picture library’, then promotes a result for the Image Library to the top of the page.

First, we’ll go to the Query Rules management page. On your search center’s upper-right-hand corner, click the gear icon, then select Site Settings.


Next, on the Site Settings page, under the Search heading, click Query Rules. Note that you may see a Search Query Rules link under Site Collection Administration. This happens if you’re the Site Collection administrator and the search center is the site collection’s root site. Don’t click that one; those Query Rules affect every site in the site collection, and for now we want to focus only on the search center site.


Now that you’re on the Query Rules page, the first question to ask is “Where will the user be?” For example, do you want to manage Query Rules for your main Enterprise Search? Or for People Search? Or Video Search? Each search experience, out-of-the-box or custom, can have its own Query Rules.

This is what we call the query’s context. You configure Query Rules for a particular context by using that first row of dropdowns in the Query Rules management page.


To manage Query Rules for a specific search experience, use the first dropdown to pick the Result Source for that experience. We’ll go into Result Sources in another post — for now, think of them as a SharePoint 2010 Federated Location plus a Search Scope. Each search experience sends queries to a Result Source, and that source guarantees results meeting certain conditions. For instance, People Search sends queries to the Local People Results source, which only returns People results.

We want our new Query Rule to fire on the main Enterprise Search. That search experience sends queries to the Local SharePoint Results source (which includes everything SharePoint crawls except People). So choose Local SharePoint Results from the first dropdown.

Next, click Add Rule to start creating your new rule.


Having picked a context, we just need to give the rule a name, then specify its conditions and actions. In other words, say when this rule will fire, and what it will do when it does. This is very similar to creating a Search Keyword in SharePoint 2010:

    1.  Give the rule a name: Image Library.
     2.  In the Query Conditions section, leave the condition type on “Query Matches Keyword Exactly”. In the textbox, type the queries we want to match, separated by semicolons: image library; picture library.
     3. In the Actions section, since we want to promote a result to the top of the page, click Add Promoted Result. These are just like Best Bets in SharePoint 2010.


4. In the Add Promoted Result dialog, fill out the title, URL, and description.


5. Click Save in the dialog, then Save in the Add Query Rule page.
And that’s it…you’ve created a Query Rule! To try it out, go to your search center and search for ‘image library’ or ‘picture library’ (note that it can take a few seconds for the Query Rule to start working).



This Query Rule, while simple, demonstrates the high-level steps for creating all Query Rules.
  1.      Pick the context (e.g., queries sent to the Local SharePoint Results source).
  2.      Specify the conditions (e.g., fire if the query exactly matches ‘image library’ or ‘picture library’).
  3.      Specify the actions (e.g., promote a result for the Image Library).



Upgrade Nintex workflows

VERIFY & CONFIGURE NINTEX WORKFLOW CONSTANTS

  1. From the home page of the upgraded site, navigate to Site Actions -> Site Settings -> Manage Workflow constants (under Nintex workflow Management)
  2. Ensure all the Nintex workflow constants (Site level and Site Collection level) are configured.


RE-PUBLISHING NINTEX WORFLOWS

  1. Access the list/document library which contain the Nintex workflow.
  2. From the ribbon, navigate to List -> Workflow settings -> Manage Workflows
  3. Open each available Nintex workflow and re-publish


Upgrade Infopath Forms

RE-PUBLISH INFOPATH FORMS

  1. Download the infopath form from the current job library, on the upgraded site.
  2. Right click on the downloaded xsn file and open the form in design mode.
  3. Click on File -> Publish -> Export Source ( to a local folder).
  4. Access the local folder where the source is stored and locate the manifest.xsf.
  5. Right click on the manifest.xsf file and open it in notepad.
  6. In the notepad, find for the url of current site and replace it with the url of the upgraded site.
  7. For example:-
  8. Replace http://apdc.oneabbott.com/showcase/workflow/BTR2020 with http://team.oneabbott.com/showcase/workflow/BTR2020
  9. Save the manifest.xsf.
  10. Right click on the manifest.xsf file and open it in the design mode.
  11. Execute the below steps for each data source added to the infopath (from the Manage Data source section).
    • Click on Manage data source link form the infopath.
    • Click on the first data source and click Modify.
    • Continue to click “Next” until the dialog display the parameters to be passed to the web service calls.
    • Verify if the url of the current site is passed as one of the parameters. If so, then replace the url with the url of the upgraded site.
  12. Save the changes to the data source and also to the manifest.xsf.
  13. Click File -> Publish -> Sharepoint library
  14. From the publish dialog select the ‘Current Job” library and publish the form.


Attach an existing content database to the farm using PowerShell script

The Mount-SPContentDatabase cmdlet attaches an existing content database to the farm. If the database being mounted requires an upgrade, this cmdlet will cause the database to be upgraded.

The default behavior of this cmdlet causes an upgrade of the schema of the database and initiates upgraded builds for all site collections within the specified content database if required. To prevent initiation of upgraded builds of site collections, use the NoB2BSiteUpgrade parameter. This cmdlet does not trigger version-to-version upgrade of any site collections.

Syntax:


Mount-SPContentDatabase [-Name] <String> [-WebApplication] <SPWebApplicationPipeBind> [-AssignmentCollection <SPAssignmentCollection>] [-AssignNewDatabaseId <SwitchParameter>] [-ChangeSyncKnowledge <SwitchParameter>] [-ClearChangeLog <SwitchParameter>] [-Confirm [<SwitchParameter>]] [-DatabaseCredentials <PSCredential>] [-DatabaseServer <String>] [-MaxSiteCount <Int32>] [-NoB2BSiteUpgrade <SwitchParameter>] [-SkipIntegrityChecks <SwitchParameter>] [-WarningSiteCount <Int32>] [-WhatIf [<SwitchParameter>]]


Example:

Mount-SPContentDatabase "MyDatabase" -DatabaseServer "MyServer" -WebApplication http://sitename


This example mounts an existing database to the sitename web application. If upgrades are required, it triggers database schema upgrade and then performs only build-to-build upgrade actions on existing site collections if required. This operation does not changed the CompatibilityLevel for existing site collections in this database.

Mount-SPContentDatabase "MyDatabase" -DatabaseServer "MyServer" -WebApplication http://sitename -NoB2BSiteUpgrade

This example mounts an existing database to the sitename web application but it prevents any site upgrades from occurring. If upgrades are required, it triggers database schema upgrades only and no build-to-build upgrade actions are performed on any site collections. This operation does not change the CompatibilityLevel for existing site collections in this database.

For More Info:

http://technet.microsoft.com/en-us/library/ff607581(v=office.15).aspx

Common SharePoint Issues & Solutions

  • PROBLEM:  When attempting to deploy a solution from Visual Studio you get an access error that includes this code – “SPUserCodeV4″
  • SOLUTION: Go to Central Administration -> System Settings. Under the “Server” heading go to “Manage Services on Server.” Look for “Microsoft SharePoint Foundation Sandboxed Code Service” and enable it. If that doesn’t work, go to the Security item in the sidebar. Under the “General Security” heading, go to “Configure service accounts.” Each service has to have a user account assigned to it. Silly. I know. Select “Windows Service – Microsoft SharePoint Foundation Sandboxed Code Service” from the dropdown, and leave YourBelovedandVeryImportantCustomer\spadmin as the account.
  • PROBLEM: When running a user control that contains UserProfileManager, you get an error that says the object cannot be found
  • SOLUTION: UserProfile Service has to be started in Central Admin. Follow the directions above, but enable both UserProfile services. You will be prompted to assign an account. Leave the account as YourBelovedandVeryImportantCustomer\spadmin. Reset IIS.
  • PROBLEM: All your list searches return null. OR a programmatic list update fails.
  • SOLUTION: Look at how you are creating your SPWeb item. If you are setting it equal to a local site, make sure the list is on that site. Here’s some handy code to get to the top level of the site without any items to dispose:
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
 {
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.List["TheNameOfYourList"];
    }
}
*Edit: SPContext objects should not be disposed, see Jason's absolutely
correct comment below!
  • PROBLEM: On a filtered list, you cannot select a value if it is the only row.
  • SOLUTION: This one eluded me for a little while. In the “Miscellaneous” category of the web part editor panel, there is a “Send first row to connected web parts…” item. Initially this seems to just control when in the page life the data is sent. HOWEVER… In typical SharePoint non-logic logic…  this actually means “select first row by default.” The data binding event occurs regardless, except the datarow is empty if there is no selected row. Oh SharePoint, you poorly-worded rascal!
  • PROBLEM: ”File Not Found” error. OR User Profile service cannot be accessed at all.
  • SOLUTION:
  • If you are only experiencing the first issue do this:
    • Go to Central Admin > Application Management > Manage Services on Server
    • Start the following:
      • Microsoft SharePoint Foundation Web Application
      • Managed Metadata Web Service
      • SharePoint Server Search
      • If you still have a file not found error, restart IIS.
      • If you STILL have a file not found error, restart SharePoint Web Services in IIS Manager manually
      • If you are having user profile service issues, do the above, then check the following:
        • Go to Start > Administrative Tools >  Services
        • Both forefront identity managers need the following settings -
          • Make sure they are both disabled (SP will start them automatically)
          • Right click the service name and go to properties. Click the “Log On” tab. Chck “This Account” and put the farm account in. On our server its UCLA\SPAdmin, password is “password”
        • Go to Start and enter “MMC” in search. Open the management console.
          • Go to “Add snapins” in the file menu
          • Add “Certificates”
            • Select Computer account for the account
            • Select local machine for the machine
          • In The following three places, look for security certificates that begin with “Forefront”
            • Personal > Certificates
            • Trusted Root Certification Authorities > Certificates
            • Trusted People > Certificates
          • If none of the certificates exist, that’s fine. If they do, delete them.
        • Follow the steps in Spence Harbar’s post here:  To delete the current user profile service and create a new one.
        • After all this reset IIS.
        • If you still can’t connect, check Central Admin > Application Management > Service Application – Configure Service Application Associations
          • Make sure the web app has the User Profile Service proxy enabled.
After you delete your current service, you may want to delete the Application Pool so that you can create a new one with a logical name. (The default is “User Profile Services Application” and it’s a pain to have to create new pools with new names all the time, but it’s nice to just clear the old one out and try again)
  • Run PowerShell as an administrator, and enter do the following:
    • enter Add-PSSnapin Microsoft.SharePoint.PowerShell
    • enter Get-SPServiceApplicationPool
    • Copy the name of the pool you want to delete
    • enter Remove-SPServiceApplicationPool “Name of my pool”
      • Keep the quotes around the name
    • If you are still experiencing problems, you may want to restart all the associated machines.
      • If you do this, you may need to:
        • go to the your DB machine and open the sql config manager. Make sure all the services are started
        • On both the APP and WFE machines, make sure user profile service and all of the sharepoint services started back up.
      • If you get an error that the configuration database is unavailable from Central Admin, then you need to double check all the services on the DB machine from sql config manager. If you miss a single one, you may not be able to access SQL.

Clean up SharePoint User Profile Store using PowerShell

Today i had a problem in my development environment for my SharePoint Projects regarding User Profile Store. My user profile was a messed up and was not available for editing in central administration. When i searched for my profile it still there but not shown for administration.  This was a really strange behavior because a couple of days it worked well. I added various new profile properties to my user profile service application. So the recreation of User Profile Service 
Application was not an option. Deletion of orphan or corrupted user profiles is not possible using Central Administration or even using avaliable PowerShell commands.

But there is a solution using PowerShell without compiled code. Using PowerShell everything what is avaliable in the server object model is avaliable. First of all two assemblies must be referenced.
These assemblies are:

These assemblies are:

Script:

/* Load required Assemblies for SharePoint Server and User Profile */
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server”)
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Office.Server.UserProfiles”)
/* Central Adminstration URL or any Web Application*/
$url = "http://myserver:Port"
/* Create a new Context Object */
$contextWeb = New-Object Microsoft.SharePoint.SPSite("http://servername");
/* Get the right Service Context */
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($contextWeb);
/* create a new connection to the UserProfileManager */
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);
/* Ger all User Profiles */
$Profiles = $UserProfileManager.GetEnumerator();
/* Loop through user profile */
foreach ($oUser in $Profiles ) {
/* Remove Profile */
$UserProfileManager.RemoveUserProfile($oUser.item("AccountName"));
}

This script can be extended to delete only specific users from user profile information. At the end I was able to solve my problem. My User Profile was deleted and recreated on first access and due profile import. Everything worked fine.

In the old days you had to write some custom command line tool to address those batch update and deletion task. With the introduction of PowerShell to SharePoint any possible administrative task could be accomplished by just use scripting.

Those assemblies could be referenced using System.Reflection and the rest of the script is quite simple SharePoint Development. So get a context object, open profile service application get all use and delete them.

Update Mysites/UserProfile user image url

I have recently had reason to update the PictureURL property value via PowerShell in SharePoint 2013 for all users in the system.
As a result, I wrote the following PowerShell script to update the property value using string replace.

You will ideally need to run this on the server with an account with the appropriate permissions to update all user profiles.

Script:

#Set up default variables
  
  #My Site URL
  $mySiteUrl = "http://mysite/"
  
  #The part of the picture URL you are trying to find
  $currentURLValue = "http://mypersonalsite"
  
  #The value that will replace the above
 $newURLValue = "http://mysite:80"
 #The internal name for PictureURL
 $upPictureURLAttribute = "PictureURL"
 #Get site objects and connect to User Profile Manager service
 $site = Get-SPSite $mySiteUrl
 $context = Get-SPServiceContext $site
 $profileManager = New-Object   Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 
 $profiles = $profileManager.GetEnumerator()
 foreach ($userProfile in $profiles) {
  if ($userProfile[$upPictureURLAttribute] -ne '') {
    
    $newPictureURL = $userProfile[$upPictureURLAttribute].toString()
    $newPictureURL  = $newPictureURL.Replace($currentURLValue, $newURLValue)
    
    write-host "Before: " $userProfile[$upPictureURLAttribute].toString() " | After: " $newPictureURL 
    
    #Get user profile and change the value - uncomment the lines below to commit the changes
    #$userProfile[$upPictureURLAttribute].Value = $newPictureURL
    #$userProfile.Commit()
  }
 }

Get the Site Collection url's for a specific Data base using Powershell script

Get-SPSite -Limit All -ContentDatabase "DBTestSiteCol" | Select URL, Owner, SecondaryOwner | Export-CSV C:\SiteInfoDB.csv -NoTypeInformation

Deploying solutions in SharePoint 2013


Disable-SPFeature -Identity "Feature1" -Url "http://sharepointsite" -force

Uninstall-SPFeature -Identity "<Feature Name>" -force

OR

Uninstall-SPFeature -Identity "<Feature ID>" -force

Uninstall-SPSolution -Identity testsolution.wsp

Remove-SPSolution -Identity testsolution.wsp

Add-SPSolution -LiteralPath "C:\Packages\testsolution.wsp"

Install-SPSolution -Identity testsolution.wsp -GACDeployment -CompatibilityLevel {14,15}

Saturday, September 27, 2014

How to display Search Results filtered on a specific Content Source

One of the things you may wish to do if you have multiple content sources is to limit a search result to a specific Content Source. For example I have created a BCS connection to a database table containing a list of products from the sample database Adventureworks product table. When I search, I only want to see results from the products table, like below.



 The first thing we would need to do is setup a content Source. For this example, I had previously created a BCS connection to the Adventureworks product table. Now I will create a search content source to point to this BCS connection. When I create a new content source on the search administration page and select BCS Service, a list of external data sources display. In this example I selected my Adventureworks data source.


When I am done it displays here in my content source list. I will need to do a full crawl to populate the index with items.



 Next, I will want to create a Result Source.  A Result Source will allow me to create a scope, or a subset of the crawled content to only return my BCS content source data. in the snapshots below I created a result source called AWResultSource. Note that I have created this result source at the search application level. this allows me to leverage the result source from any site collection. I could also create this same kind of filter at the result page or site collection level which we will see later in this blog.

  

 On the new Result Source page I have chosen "Local SharePoint" and "SharePoint Search Results" and then I will select "launch Query Builder". This will bring up the page to build the actual filter. When I first go to select my property from the property filter, the content source property does not show up. I needed to select "Show all managed properties".

  

 Now I select the ContentSource property, choose Manual value, and enter the name of the content source I created earlier. On the right, you will get a sample of the results to make sure you are on track. If you get a nasty message about not being able to show a preview, you will need to turn on the "Search Server Webpart and properties" feature in site settings for the admin site.

 

The feature name:



 At this point, I have a content source to index the content, and I have a result source to filter search results for the content.

Now I will add it to a search center site. The rest of this blog is focused on modifying the search center site collection.
For your reference, go to the Site Settings page for your search center and select "Manage Result Sources". You will note that the Result Source I created above is in the list. If I had wanted to, I could have just added it here and it would be available for this site collection.



 At this point I need a page to show the filtered results with. This is the interesting part, the settings for the filter to only show the results for the content source is part of the results page. Now lets create the page. Go to the Pages library under Site Contents for the search center site. Select Files, New Document, and then Page. Note that the page layout is a Search Results page layout. choose a name and save. In the screenshot below I created a page called awresultpage.



Now we will edit the page to set our filter. Edit the page and choose edit the webpart for the Search results webpart. in the "Properties for Search Results" section, select change query.




 For "Select a query" choose the result source. In this case it would be the AWresultSource we created earlier. This will set the filter on the results we want. Again I should see a search result preview. Note that I could have set the result source filter right here instead of at the service application level. You have lots of options for the visibility level for returning a subset of the crawled index.



The last thing I need to do is to modify the Search Settings page under site settings to show the menu item on the search page. Here I will add a link under Configure Search Navigation.



 The link points to the results page I created.



Now when I go to the search page, I see products as a menu option. and when I click it, I see the results for the content source.

 

Restart Microsoft SharePoint Foundation Web Application Service. Error

I wanted to share some information in case you are planning to restart “Microsoft SharePoint Foundation Web Application” service or any other service and got stuck with status showing “Stopping” you can use power shell command mentioned below.

I had a situation when “Microsoft SharePoint Foundation Web Application” service was Showing “Stopping” status for more than 7 hours and even reboot and IIS reset did not do anything. I was able to restore service in normal condition using command mentioned below.

Note: In case you are planning to restart “Microsoft SharePoint Foundation Web Application” service better back up your IIS and Virtual directory folder to be on the safe side.

If you have the same situation where some service is stuck use power shell to stop it

$svc = Get-SPServiceInstance | where {$_.TypeName -like "*Foundation Web*"}
$svc.Status = "Offline"
$svc.Update()

You can use PowerShell to start it again

$svc = Get-SPServiceInstance | where {$_.TypeName -like "*Foundation Web*"}
$svc.Status = "Online"
$svc.Update()

In order to get virtual directories back run this PowerShell command

$wa = Get-SPWebApplication http://webAppUrl
$wa.ProvisionGlobally()

Update Redirect Page url programatically

Below is the code to update the Redirect url of a page in sharepoint.

Code snippet:

SPSite site = new SPSite("http://sharepointsite");
SPWeb web = site.OpenWeb();
SPList library = web.Lists["Pages"];
SPQuery query = new SPQuery();
query.Query = "<<Where><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>Redirect Page</Value></Eq></Where><OrderBy><FieldRef Name='Created' Ascending='true' /></OrderBy>";
query.RowLimit = 4;
SPListItemCollection items = library.GetItems(query);
foreach (SPListItem item in items)
  {
     if (item.ContentType.Name == "Redirect Page")
         {
              item.File.CheckOut();
              SPFieldUrlValue urlValue = new SPFieldUrlValue();
              urlValue.Description = "https://www.google.com"; // ValidURL is a correct URL that I've tested
              urlValue.Url = "https://www.google.com";
              item["Redirect URL"] = urlValue;
              item.SystemUpdate(false);
              item.File.CheckIn("", SPCheckinType.MajorCheckIn);                  
         }              

  }