Thursday, November 29, 2012

Remove sharepoint site and custom list from the search result

Today, I came across the requirement where I have to stop site to be crawl in search


Go to the Site Actions=> Site Settings => Site Administration => Search and offline availability.
share1.gif

We can manage the visibility of site and site's web page's web parts for search.

share2.gif
Using SharePoint object model:


share3.gif



Using Powershell:

#---------StopSearch

$site=Get-SPSite "http://servername:1111/"
$web=$site.RootWeb;
$web.AllowAutomaticASPXPageIndexing=$true
$web.ASPXPageIndexMode=[Microsoft.SharePoint.WebASPXPageIndexMode]::Never
$web.NoCrawl=$false
$web.Update()


#---------StartSearch
$site=Get-SPSite "http://servername:1111/"
$web=$site.RootWeb;
$web.AllowAutomaticASPXPageIndexing=$false
$web.ASPXPageIndexMode=[Microsoft.SharePoint.WebASPXPageIndexMode]::Never
$web.NoCrawl=$true
$web.Update()




For SharePoint Custom list:

Go to : 
  1. List Settings page, under General Settings, click Advanced settings.
  2. In the Search section, under Allow items from this list to appear in search results, select Yes to include all of the items in the list or library in search result or No to exclude all items from search results.

Using SharePoint Object Model
SPList list = ...    

list.NoCrawl = true;    
list.Update()


Using Powershell:


$site = Get-SPSite http://siteColl    
    $site | Get-SPWeb -Limit ALL | ForEach-Object {   
        foreach ($list in $_.lists) 
        {                  
                    $list.NoCrawl = $true
                    $list.Update()
        }
    }

    $site.Dispose()




Custom aspx page with default master page in SharePoint

I had a requirement to create custom aspx page and deploy to _layouts folder.

Got help from this 
http://www.codeproject.com/Tips/312544/How-To-Add-Custom-ASP-NET-Page-Using-Layouts-Folde

Page is deployed to _layouts folder.

Code in .aspx file


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ItemDetails.aspx.cs" Inherits="namespace,Version=1.0.0.0, Culture=neutral, PublicKeyToken=3ffee3a64ae3d939" Debug="true" MasterPageFile="~/_layouts/v4.master" %>

<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages, 
Version=14.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderMain" runat="server">
   main file content
</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" runat="server" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea">
</asp:Content>

Issue I faced was page CSS.

be sure to use v4.master for SharePoint 2010 and default.master for MOSS.


else page will lose the css part.