Wednesday, June 13, 2012

SharePoint SPWeb Property ParserEnabled

ParserEnabled :- property controls demotion and promotion.
Promotion :- The process of extracting values from properties of a document and writing those values to corresponding columns on the sharepoint list or document library where the document is stored.

Demotion :- The same process in reverse.Read sharepoint list or library columns values and written to document properties.

When ParserEnabled property false there will not be any property demotion and promotion, which means metadata and document file properties will not be in sync.

PowerShell way of Disabling and enabling this property:
Disable ParserEnabled property:
    [system.reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
    $site = new-object Microsoft.SharePoint.SPSite("http://mossweb/sites/test")
    $site.RootWeb.ParserEnabled = $false
    $site.RootWeb.Update()

Enable ParserEnabled property or 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://sharepoint-portal"))
{
    using (var web = site.OpenWeb())
    {
       SPFile file = web.GetFolder("Documents").Files["mydoc.docx"]; 
       using (var fs = new FileInfo(@"C:\Documents\mydoc.docx").OpenRead())
 
       {
        documentBytes = ..... // get the documents bytes
       }
       web.ParserEnabled = false;
       web.Update();
       file.SaveBinary(documentBytes);
       web.ParserEnabled = true;  
       web.Update();
    }
}
 
Use the ‘Comments’ form to share your thoughts.
Share:

7 comments:

  1. YOu just totally saved my project! Thanks!

    ReplyDelete