SharePoint : Document ID link redirection fails for some file types (like png, jpg, mpp, etc)

In one of the application, we are using Document ID for permalink in document libraries. We are storing documents of different file types (like docx, xlsx, pdf, png, jpg, jpeg, etc) in document library. SharePoint search is set up in our server which crawls the data every half an hour.

Case 1 :

When any document (of type docx, xlsx, pdf) is added in document library, unique Document ID generated for document. When I clicked on that link, that document is either opened (if client application installed like pdf, office application) or downloaded.

Case 2 :

But when I added documents of file types png, jpg, jpeg or mpp in document library and clicked on Document ID, it works same as Case 1. After half an hour search crawls the site. When I clicked again on Document ID link, it opens the display form of that document instead of opening or downloading the document. But the Case 1 is still working even after crawling happens.

I search for the issue in internet and found below article in msdn :

Document ID Lookup Behavior

 SharePoint Server 2010 takes a two-part approach when the document ID service looks up document IDs to provide the best balance of document IDs that work immediately and those that work across broad scopes:
  • Search. Find an item across any location that belongs to the current search scope. Search generally performs better as a cross-list query. However, search is only as reliable as its last index. Therefore, if an item was added but has not yet been indexed by search, it does not appear in search results. Additionally, if an item was moved since the last time it was indexed by search, then the old (and now broken) URL appears in search results.
  • Lookup specific to the ID provider. When an item cannot be retrieved by using search (for example, if it has not been indexed yet), SharePoint Server 2010 calls back to the document ID provider and allows it to use its own lookup logic. This enables providers who want to use IDs that work before search indexing is run on the last items to look them up. The provider determines whether to perform lookups in this way and what the most effective logic is for doing so.

After reading above statement it clear that SharePoint Search is not properly indexing the document of file types png, jpg, jpeg, mpp.

You can read below article to know more about default File Types supported  by SharePoint Search :

SharePoint Search 2013 File Types

Solution

To solve this issue, we have to go SharePoint server and follow below steps:

  1. Open Central Administration -> Application Management .
  2. Click on “Manage service applications
  3. Open Search Service Application
  4. On left section, under Crawling section click on File Types. Here you will see all file types which SharePoint Search understands and crawled properly.
  5. Click on “New File Type” and add all extensions one by one without any dot.
  6. Now click on Content Sources and start Full Crawl on your content source which is created for your web application.
  7. Once Full Crawl completed, check those documents which are failed to open earlier. When you clicked again on Document ID link, they will work as expected without redirecting to display form.

Note : Repeat above steps for other file types which are facing similar issue.

References : 

https://msdn.microsoft.com/en-us/library/office/ee559302(v=office.14).aspx

SharePoint : Get User’s login name from claims encoded value

There are sometimes scenarios where we have to get user’s login name and we have only claims encoded value (like this i:0#.w|domain\username or i:0#.f|membershipprovider|abc.xyz@comp.com). In SharePoint 2013 / 2010, there is SPClaimProviderManager class available which can decode the claims and provide user’s login name.

I have created a method, which accepts claims encoded value as parameter and returns user’s login name (only if claims are resolved properly).

private string GetUsernameFromClaim(string claimsEncodedUsername)
{
 try
 {
 SPClaimProviderManager mgr = SPClaimProviderManager.Local;
 if (mgr != null)
 {
 if (SPClaimProviderManager.IsEncodedClaim(claimsEncodedUsername))
 {
 // return the normal domain\username without any claims identification data
 return mgr.DecodeClaim(claimsEncodedUsername).Value;
 }
 }
 }
 catch (Exception ex)
 {
 return claimsEncodedUsername; // Or just return the original username.
 }

 // Return the original username value if it couldn't be resolved as a claims username
 return claimsEncodedUsername;
}

Note : Add namespace “Microsoft.SharePoint.Administration.Claims” to use above class.

Read user claims information in SharePoint 2013

In this article, we will see how to read user claims in SharePoint 2013. For this I have prepared one httphandler, which will read the claims information of current logged in user (authentication type windows, forms or third party trusted provider).

using Microsoft.IdentityModel.Claims;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration.Claims;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace SSONamespace
{
    class SSOAuthenticationExample : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);
        }

        void context_PreRequestHandlerExecute(object sender, EventArgs e)
        {            
            string requestUrl = HttpContext.Current.Request.Url.ToString();
            IClaimsIdentity ci = (IClaimsIdentity)HttpContext.Current.User.Identity;
            List<Claim> claimCollection = ci.Claims.OfType<Claim>().Select(x => x).ToList();

	/*Uncomment these lines to see all claims entries */
            //string text = string.Empty;
            //foreach (Claim item in ci.Claims)
            //{
            //    text += item.ClaimType + " : " + item.Value + " | ";
            //}

            //System.IO.File.WriteAllText(@"C:\SSOClaims.txt", text);
		
		//fetch information from claims
            string userName = claimCollection.Where(x => x.ClaimType.ToLower().Contains("userid")).Select(y => y.Value).FirstOrDefault();
         }

        public void Dispose() { }

    }
}

Now deploy this code and add below entry in web.config file of web application :

<system.web>
  <httpModules>
    <add name="SSONamespaceModule" type="SSONamespace.SSOAuthenticationExample , SSONamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3af8d8e2f9e8b6c3"  precondition="integratedmode" />
  </httpModules>
</system.web>

Note : Replace PublicKeyToken value from your own project’s PublicKeyToken

SharePoint Search 2013 File Types

SharePoint Search 2013 default supports below mentioned lists of file types. The crawl component only crawls those file types which are mentioned in “File Types” section of Search Administration” page. The content processing component indexed the content of file only if built-in or third party Format Handler (iFilter) is installed in SharePoint server

File format Format ID File name extension File name extension listed on the Manage File Types page by default
Email message eml .eml Yes
Email message nws .nws Yes
HTML html .ascx Yes
HTML html .asp Yes
HTML html .aspx Yes
HTML html .css No
HTML html .hta No
HTML html .htm Yes
HTML html .html Yes
HTML html .htw No
HTML html .htx No
HTML html .jhtml No
HTML html .stm No
MHTML document mhtml .mht Yes
MHTML document mhtml .mhtml Yes
Microsoft Excel xlb .xlb No
Microsoft Excel xlc .xlc No
Microsoft Excel xls .xls Yes
Microsoft Excel xlsb .xlsb Yes
Microsoft Excel xlsm .xlsm Yes
Microsoft Excel xlsx .xlsx Yes
Microsoft Excel xlt .xlt No
Microsoft OneNote one .one No
Microsoft PowerPoint pot .pot No
Microsoft PowerPoint ppa .ppa No
Microsoft PowerPoint pps .pps No
Microsoft PowerPoint ppt .ppt Yes
Microsoft PowerPoint pptm .pptm Yes
Microsoft PowerPoint pptx .pptx Yes
Microsoft Publisher pub .pub Yes
Microsoft Word doc .doc Yes
Microsoft Word docm .docm Yes
Microsoft Word docx .docx Yes
Microsoft Word dot .dot Yes
Microsoft Word dotx .dotx Yes
Microsoft XPS xps .xps No
Open Document Chart odc .odc Yes
Open Document Presentation odp .odp Yes
Open Document Spreadsheet ods .ods Yes
Open Document Text odt .odt Yes
Outlook item msg .msg Yes
Portable Document Format pdf .pdf Yes
Rich Text Format rtf .rtf No
Text txt .asm Yes
Text txt .bat No
Text txt .c No
Text txt .cmd No
Text txt .cpp No
Text txt .csv Yes
Text txt .cxx Yes
Text txt .def Yes
Text txt .h No
Text txt .hpp No
Text txt .lnk No
Text txt .mpx No
Text txt .php No
Text txt .trf No
Text txt .txt Yes
Text txt .url No
TIFF tiff .tif No
TIFF tiff .tiff No
Visio vdw .vdw Yes
Visio vdx .vdx Yes
Visio vsd .vsd Yes
Visio vsdm .vsdm Yes
Visio vsdx .vsdx Yes
Visio vss .vss Yes
Visio vssm .vssm Yes
Visio vssx .vssx Yes
Visio vst .vst Yes
Visio vstm .vstm Yes
Visio vstx .vstx Yes
Visio vsx .vsx Yes
Visio vtx .vtx Yes
XML xml .jsp Yes
XML xml .mspx No
XML xml .rss No
XML xml .xml Yes
ZIP zip .zip Yes

Important Points:

  • The file will not crawled and parsed if it is not listed in “File Types” section and no Format Handler (iFilter) is installed respectively. For example, you had uploaded a file of type *.twbx in SharePoint site and “twbx” is not listed in “File Types” section then it was not crawled and not available in crawl logs of SharePoint search. To make it crawl, you need to add “twbx” in “File Types” section. After adding the file type, restart the SharePoint Search service and starts Full Crawl. The file will now be available in crawl logs and you can search it with filetype:twbx.
  • The content of file can only be parsed if built-in or third party iFilters are installed. To implement custom iFilter you can read this article : http://blogs.technet.com/b/sharepointdevelopersupport/archive/2013/05/13/how-to-implement-a-custom-ifilter-in-sharepoint-2013.aspx

References:

Default crawled file name extensions and parsed file types in SharePoint Server 2013

 

Creating and configuring SharePoint 2013 search using powershell

In previous post of Sharepoint search overview, we knows about the SharePoint search architecture and its different components. Today, we are going to create and configure about Search service application (SSA) using powershell.
SharePoint search service application crawls the content of site collections and provides search functionality. The powershell needs to run in SharePoint management shell in SharePoint server. The script is suitable only for single server SharePoint farm.

# Get App Pool
$saAppPoolName = "SearchAppPool"

# Search Specifics, suitable for single server farm
$searchServerName = (Get-ChildItem env:computername).value
$serviceAppName = "Search Service Application"
$searchDBName = "SearchService_DB"

# Grab the Application Pool for Service Application Endpoint
$saAppPool = Get-SPServiceApplicationPool $saAppPoolName

# Start Search Service Instances
Write-Host "Starting Search Service Instances..."
Start-SPEnterpriseSearchServiceInstance $searchServerName
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

# Create the Search Service Application and Proxy
Write-Host "Creating Search Service Application and Proxy..."
$searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $saAppPoolName -DatabaseName $searchDBName
$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$serviceAppName Proxy" -SearchApplication $searchServiceApp

# Clone the default Topology (which is empty) and create a new one and then activate it
Write-Host "Configuring Search Component Topology..."
$clone = $searchServiceApp.ActiveTopology.Clone()
$searchServiceInstance = Get-SPEnterpriseSearchServiceInstance
New-SPEnterpriseSearchAdminComponent –SearchTopology $clone –SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
$clone.Activate()