Wednesday, April 25, 2012

SharePoint SPWeb Property ParserEnabled

ParserEnabled property controls demotion and promotion.
Promotion refers to the process of extracting values from properties of a document and writing those values to corresponding columns on the list or document library where the document is stored.
Demotion is the same process in reverse. Values are read from list columns and written to document properties.
When ParserEnabled property false there will not be any property demotion and promotion. it means metadata and document file properties will not be in sync.

Disabling and enabling this property using PowerShell:
To disable this property:

    [system.reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $site = new-object Microsoft.SharePoint.SPSite("http://mossweb/sites/test")
    $site.RootWeb.ParserEnabled = $false
    $site.RootWeb.Update()

To enable document property promotion:

    $site.RootWeb.ParserEnabled = $true
    $site.RootWeb.Update()

Note:
Disabling ParserEnabled affect:
  1. We can't search in document library using Office document properties.
  2. When you upload image file. Thumbnail will not be generated.
  3. When you save a list template, You will not see it in list template gallery.

If you need to disable this property you need to take care of its effect. Disable it only in special sites. if you want it when you upload document using code disable it temporary using code like below:

using (var site = new SPSite("http://portal"))

using (var web = site.OpenWeb())
{
   SPFile file = web.GetFolder("Documents").Files["mydoc.docx"]; 
   using (var fs = new FileInfo(@"E:\Documents\mydoc.docx").OpenRead())

   {
    documentBytes = ..... // get the documents bytes
   }
   web.ParserEnabled = false;
   web.Update();
   file.SaveBinary(documentBytes);
   web.ParserEnabled = true;  
   web.Update();
}



No comments: