Navigation

Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Friday, 27 March 2015

SharePoint 2013 Search new feature

UI Improvement 
Without having to open each search result, users can quickly identify useful results in ways such as the following:
  • Users can rest the pointer over a search result to preview the document content in the hover panel to the right of the result.
  • Users can quickly distinguish search results based on their type. For example, Microsoft Office documents display the application icon in front of the title of the search result. Newsfeed conversation results display the number of replies and the number of likes to the right. Site results list the top links that users often click on the site. People in results show the picture and the Lync availability status to the left.
  • By default, certain types of related results are displayed in groups called result blocks. A result block contains a small subset of results that are related in a particular way. For example, results that are PowerPoint documents appear in a result block when the word "presentation" is one of the search terms. Administrators and site owners can also create result blocks to group other results. Like individual search results, you can promote result blocks or rank them with other results.
Search helps users quickly return to important sites and documents by remembering what they have previously searched and clicked. The results of previously searched and clicked items are displayed as query suggestions at the top of the results page.
In addition to the default manner in which search results are differentiated, site collection administrators and site owners can create and use result types to customize how results are displayed for important documents. A result type is a rule that identifies a type of result and a way to display it.
Site collection administrators and site owners can use display templates to customize the appearance of search results by using an HTML editor, and they can customize the behavior of search results by using JavaScript. They can specify display templates that determine how result types appear.

Relevance Improvement
A search result, suggestion, or recommendation is more relevant when it better satisfies the intent of the person who issues the query. SharePoint Server 2013 improves relevance in areas such as freshness of search results, linguistics, and document parsing. It also improves relevance in the following areas:
  • New ranking models
  • Analysis of content and user interaction
  • Query rules
  • Result sources
New Search Architecture

SharePoint Server 2013 introduces a new search architecture that includes significant changes and additions to the search components and databases. For examples and more information, see the Search technical diagrams in Technical diagrams for SharePoint 2013.

Search health report

SharePoint Server 2013 provides many query health reports and crawl health reports. In SharePoint Server 2010 and FAST Search Server 2010 for SharePoint, similar reports were called Search Administration Reports. For more information, see View search diagnostics in SharePoint Server 2013.

More flexible search schema

By defining crawled properties, managed properties, and the mappings between them, the search schema determines how the properties of crawled content are saved to the search index. Crawled properties and how these are mapped to managed properties define how to transform crawled content into managed properties. The search index stores the contents of the managed properties. The attributes of the managed properties determine the search index structure.
SharePoint Server 2013 introduces new attributes that you can apply to managed properties, such as sortable and refinable. The sortable attribute reduces the time that is required to return large search result sets by sorting results before they are returned. The refinable attribute enables you to create a refiner based on a particular managed property.
In SharePoint Server 2013, you can have multiple search schemas. The main search schema is defined at the Search service application level. Site collection administrators can create customized search schemas for different site collections.
Changes in Crawling
SharePoint Server 2013 includes many changes and improvements related to crawling content.
Continuous Crawl
In SharePoint Server 2013, you can configure crawl schedules for SharePoint content sources so that crawls are performed continuously. Setting this option eliminates the need to schedule incremental crawls and automatically starts crawls as necessary to keep the search index fresh. Administrators should still configure full crawls as necessary. For more information, see Manage continuous crawls in SharePoint Server 2013.
Host distribution rules removed
In SharePoint Server 2010, host distribution rules are used to associate a host with a specific crawl database. Because of changes in the search system architecture, SharePoint Server 2013 does not use host distribution rules. Instead, Search service application administrators can determine whether the crawl database should be rebalanced by monitoring the Databases view in the crawl log.
Removing items from search index
In SharePoint Server 2010, Search service application administrators could remove items from the search index by using Search Result Removal. In SharePoint Server 2013, you can remove items from the search index only by using the crawl logs.

Wednesday, 25 March 2015

Creating a simple Custom Field Type for SharePoint 2010 using Visual Studio

Email Validation Field
1.      In Visual Studio, create an Empty SharePoint Project. Give a suitable name for your project and here its “CustomNewFileld 
2.      Right-click the project name in Solution Explorer and select Add | New Item
3.      In the Add New Item dialog box, select Visual C#
4.      Select Class from the template and give name as EmailField.csn 
5.      Coding EmailField.cs file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Text.RegularExpressions;
namespace CustomNewFileld
{
    public class EmailField : SPFieldText // Base Class
    {
        public EmailField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        { // Default Constructor
        }
        public EmailField(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        { // Default Constructor
        }
       // If you need default value in NewForm you can use the below method
       /*public override string DefaultValue
        {            get{ return "Test"; }        }*/

·         GetValidatedString is used for data serialization logic and for field validation logic that is specific to a custom field type to convert the field value object into a validated, serialized string.
·         GetValidatedString method check whether the field is required and, if it is the overriddenmethod throws an SPFieldValidationException exception when the value is null or an empty String.
·         SPFieldValidationException when the value is not valid, causing an error message to appear beneath (under) the invalid field.
        public override string GetValidatedString(object value)
        {
            String Email = (String)value;
            bool result = isEmailID(Email);
            if (Email == "")
                throw new SPFieldValidationException("Field should not be empty");
            else if (result != true)
            {
                throw new SPFieldValidationException("Enter valid Email");
            }
            else
            {
                return value.ToString();
            }
           
        }
        public static bool isEmailID(string inputEmail)
        {
            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputEmail))
                return (true);
            else
                return (false);
        }
    }
}
6.      In Solution Explorer, right-click the project name and select Add, then SharePoint Mapped Folder 
7.      Use the tree control that opens to map the folder to TEMPLATE\XML and click OK.
8.      Right-click the new XML folder (not the project name) in Solution Explorer and select Add | New Item.
9.      In the Add New Item dialog box, select Visual C# and select an XML file; give the name as Fldtypes_EmailField.xml.

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
       <FieldType>
              <Field Name="TypeName">Email</Field>
              <Field Name="ParentType">Text</Field>
              <Field Name="TypeDisplayName">Email</Field>
              <Field Name="TypeShortDescription">Email Validation</Field>
              <Field Name="UserCreatable">TRUE</Field>
              <Field Name="ShowOnListCreate">TRUE</Field>
              <Field Name="ShowOnSurveyCreate">TRUE</Field>
              <Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
              <Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
              <Field Name="FieldTypeClass">          CustomNewFileld.EmailField,$SharePoint.Project.AssemblyFullName$</Field>
              </FieldType>
</FieldTypes>

CustomNewFileld - Namespace name (Mostly the project name).
EmailField .cs Filename which has the default constructors.
Email Validation – Name to be displayed in creating a New Column.
10. Right-click the References node in Solution Explorer, click Add Reference, and select PresentationFramework.dll on the .NET tab in the Add Reference dialog box. Click OK.
11. Finally Build and Deploy solution.

SharePoint Object Hierarchy

  • SPFarm – Represents farm-level settings.
    • Class and global, static object
    • Cannot create or dispose
    • Will only be used if creating Admin type of tools.
  • SPService – Represents farm wide services
    • SPWebService is a type of SPService – Each Web application belongs to an SPWebService.
    • Forms, Access, PerformancePoint, Search, Excel, User Profile, Business DataConnectivity, Managed Metadata.
    • Will only be used if creating Admin type of tools.
    • It is a base class that other specific services inherit.
  • SPWebApplication – Maps to IIS Web sites
    • Can create and delete web applications (usually done in admin).
  • SPSite – Represents Site Collections
    • Each have a RootWeb
    • Contains site level features and solutions
    • Instantiate by:
      • Using it’s constructor.
      • Member of Sites collection of the SPWebApplication.
      • Referencing the current site context.
    • Usually represents a security boundary.
  • SPWeb – Represents SharePoint Sites
    • Consider SPWeb objects as storage units.
    • Contains pages, lists, libraries, subwebs.
    • Instantiate by:
      • RootWeb of SPSite object.
      • Member of AllWebs collection in SPSite.
      • Return value of the OpenWeb method of a SPSite object.
      • Referencing the current context web.
  • SPList – Primary container for data.
    • Contains data and exposes properties.

Both SPSite and SPWeb Objects need to be disposed because they have underlying COM objects thatperform some tasks.

Tuesday, 24 March 2015

Basic PowerShell for SharePoint and its Equivalent STSADM Command used in Earlier Version



This is a simple list down of basic PowerShell commands used in command line deployments in SharePoint. [SP 2010 and 2013]  &
The equivalent STSADM commands used in SharePoint 2007 ... back in the day ;)


1. Adding a new WSP to farm solution

SP 2010/2013 PowerShell
 Add-SPSolution -LiteralPath "C:\FolderName\Solution.wsp"
SP 2007 
Stsadm
 stsadm -o addsolution -filename "Solution.wsp"
[Assuming command runs from the correct folder location]


2. Deploy WSP 

SP 2010/2013 PowerShell
 Install-SPSolution -Identity "Solution.wsp-WebApplication "http://WebSiteUrl" -CASPolicies -GACDeployment -Local -Force

AllWebApplications vs WebApplication - All allows the wsp to be deployed in all SP web applocations. WebApplication - allows the wsp to be deployed to a target web app
CASPolicies - Allows Code Access Security Policies to be deployed [optional]
GACDeployment - Allows DLL installation in the global assembly cache [optional]
Force [optional]
Local - Deploys only in the current server [optional]
SP 2007 
Stsadm
stsadm -o deploysolution -name "SolutionName" -url "Site URL" -immediate -allowgacdeployment -allowcaspolicies -force

instead of -url, you can use -allcontenturls 
instead of -immediate, you can use -time "time to deploy"

GACDeployment - Allows DLL installation in the global assembly cache [optional]


3. Activate feature

SP 2010/2013 PowerShell
 Enable-SPFeature –identity "FeatureName" -URL http://WebSiteUrl
SP 2007 
Stsadm
 stsadm -o activatefeature -id feature_ID -url http://WebSiteUrl -force
[Instead of -Id, you can use -filename or -name with appropriate values]


4. De-activate feature

SP 2010/2013 PowerShell
 Disable-SPFeature –identity "FeatureName" -URL http://WebSiteUrl
SP 2007 
Stsadm
stsadm -o deactivatefeature -id feature_ID -url http://WebSiteUrl
[Instead of -Id, you can use -filename or -name with appropriate values]



5. Retract WSP 

SP 2010/2013 PowerShell
Uninstall-SPSolution -Identity "Solution.wsp" -WebApplication http://WebSiteUrl
SP 2007 
Stsadm
stsadm -o retractsolution -name "Solution.wsp" -url http://WebSiteUrl -immediate 
[Instead of -immediate, you can use -time "TimeToRun"]



6. Remove WSP from SharePoint farm

SP 2010/2013 PowerShell
Remove-SPSolution -Identity "Solution.wsp"
SP 2007 
Stsadm
stsadm -o deletesolution -name "Solution.wsp"

Get-SPWebApplication is not recognised as the name of the cmdlet

When you try to execute SharePoint specific commands through PowerShell, might come across a message

"Get-SPWebApplication is not recognized as the name of the cmdlet ......"

The SP specific commands are not being recognized in PowerShell at this point. Adding a snap in would do the trick. Type the below command in your PowerShell  window.

Add-PSSnapin Microsoft.Sharepoint.Powershell

That's it. Provided that the rights in DB are there, you should be able to execute SharePoint based commands now.

New Farm Administrator - could not be updated because the current user is not a farm administrator

You might have come across situations where a new farm administrator via the Central Admin, but the granted rights to the user account does not work as you expected.

In SharePoint 2010, even though a user is added as farm administrator, you might get an error in the log as "could not be updated because the current user is not a farm administrator".

This is due to the ShrarePoint 2010 security feature, which blocks modifications to any object inheriting from SPPersistedObject in the Microsoft.SharePoint.Administration namespace.

To resolve this issue, run the below script in powershell, which grants access.


function RemoteAdministrator-GiveAccess()                                                                                                
{                                                                                                                                                                 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null                              
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration") > $null       
                                                                                                                                                                   
    $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService                        
    $contentService.RemoteAdministratorAccessDenied = $false                                                                   
    $contentService.Update()                                                                                                                        
}                                                                                                                                                                 
                                                                                                                                                                   
RemoteAdministrator-GiveAccess       

Monday, 12 January 2015

Event Receivers BeforeProperties or AfterProperties



These are the values of the properties in List events:


ListBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo ValueNo ValueNull
ItemAddedNo ValueNo ValueNew Value
ItemUpdatingOriginal ValueChanged ValueOriginal Value
ItemUpdatedOriginal ValueChanged ValueChanged Value
ItemDeletingNo ValueNo ValueOriginal Value
ItemDeletedNo ValueNo ValueNull

And here are the properties available in Library events:


LibraryBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo ValueNo ValueNull
ItemAddedNo ValueNo ValueNew Value
ItemUpdatingOriginal ValueChanged ValueOriginal Value
ItemUpdatedOriginal ValueChanged ValueChanged Value
ItemDeletingNo ValueNo ValueOriginal Value
ItemDeletedNo ValueNo ValueNull
-------------------------------------------
ListBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo valueNew valueNull
ItemAddedNo valueNew valueNew value
ItemUpdatingNo valueChanged valueOriginal value
ItemUpdatedNo valueChanged valueChanged value
ItemDeletingNo valueNo valueOriginal value
ItemDeletedNo valueNo valueNull

No value means that column value in the hash table was not available.
New value means that the correct value for the column was available.
Changed value means that the correct updated value was available.
Original value means that the correct original value was available.



Here is the same test against a document library:
LibraryBeforePropertiesAfterPropertiesproperties.ListItem
ItemAddingNo valueNo valueNull
ItemAddedNo valueNo valueNew value
ItemUpdatingOriginal valueChanged valueOriginal value
ItemUpdatedOriginal valueChanged valueChanged value
ItemDeletingNo valueNo valueOriginal value
ItemDeletedNo valueNo valueNull