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();
}



Sharepoint prompt authentication when opening Word / Excel files from website

I faced Problem with internet sites run with anonymous users. SharePoint prompt with window authentication when users opening a Word / Excel. If the window is dismissed then the document continues to open normally.
Reason for this behaviour ViewFormPagesLockDown feature, this feature removes the View Application Pages permission, and the Use Remote Interfaces permission. The View Application Pages is the one that allows our anonymous users to access the Forms pages.

To solve this problem deactivate  ViewFormPagesLockDown:
stsadm -o deactivatefeature -url http://siteurl -filename ViewFormPagesLockDown\feature.xml

But this solution will give anonymous users permission to all FormPages for lists. For better solution need to give anonymous users View Application Pages for only needed. But you can't find direct way to do that, You can use free tools like SharePoint Manager to update this permission.



Tuesday, April 24, 2012

Content Editor web part in onet.xml

When tried to add a content editor web part to site definition. It works with me for simple content but when try to add tagged content like HTML it failed. After some Investigation I found solution by putting content into value tag <Value> instead of putting it direct into content property like this example:



<AllUsersWebPart WebPartZoneID="SurveyBtn" WebPartOrder="5">
        <![CDATA[
        <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Title>Content Editor</Title>
            <FrameType>None</FrameType>
            <Description>Use for formatted text, tables, and images.</Description>
            <IsIncluded>true</IsIncluded>
            <ZoneID>WebPartZoneMiddleR</ZoneID>
            <PartOrder>5</PartOrder>
            <FrameState>Normal</FrameState>
            <Height />
            <Width />
            <AllowRemove>true</AllowRemove>
            <AllowZoneChange>true</AllowZoneChange>
            <AllowMinimize>true</AllowMinimize>
            <AllowConnect>true</AllowConnect>
            <AllowEdit>true</AllowEdit>
            <AllowHide>true</AllowHide>
            <IsVisible>true</IsVisible>
            <DetailLink />
            <HelpLink />
            <HelpMode>Modeless</HelpMode>
            <Dir>Default</Dir>
            <PartImageSmall />
            <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
            <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
            <IsIncludedFilter />
            <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
            <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
            <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
              <Value>
               &lt;div class=&quot;SurveyLocation&quot;&gt;&lt;a href=&quot;../Surveys&quot;&gt;&lt;img src=&quot;/_LAYOUTS/PMO.Departments/images/icn_survey.jpg&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
              </Value>
            </Content>
            <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
          </WebPart>
]]>
      </AllUsersWebPart>

Error with SharePoint 2010 TaxonomyPicker.ascx

I found error in event log with machine has a SharePoint 2010 error is:


Load control template file /_controltemplates/TaxonomyPicker.ascx failed: Could not load type  'Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker' from assembly 'Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral,  PublicKeyToken=71e9bce111e9429c'.


Solution:
  1. open file /14/ControlTemplates/TaxonomyPicker.ascx and replace , and replace with a comma. (decoded value)
  2.  After updating service pack this solution not applicable SharePoint used another control and the above error still appear. You need to remove this file to unknown extension like TaxonomyPicker.ascx_  so that we do not try to recompile it each time the AppPool is started. T


Sunday, April 22, 2012

Configure Forms Based Authentication (FBA) with SharePoint 2010

SharePoint 2010 FBA, is different in configuration than WSS 3.0 or MOSS 2007. It needs create web applications Claims based Authentication.  
Classic Mode Authentication: It is only integrated windows authentication.
Claims Based Authentication: It is based Windows Identity Foundation. It enables authentication for any type of authentication, It is also provides the capability to have multiple authentication in a single URL.

You can convert a web application from Classic Mode Authentication to Claims Based Authentication. However, that can only be done using PowerShell commands:
http://blogs.technet.com/b/mahesm/archive/2010/04/07/configure-forms-based-authentication-fba-with-sharepoint-2010.aspx

   
    $App = get-spwebapplication “URL”
    $app.useclaimsauthentication = “True”
    $app.Update()

Here is the steps of configuring FBA. I am assume here you have already created a membership and role Manager:
  1. A. Creating web application using Central administration
    • Open Central Administration Console.
    • Click on Manage Web application Under Application Management.
    • Click on new on the Ribbon.
    • Chose Claims based Authentication From the top of the page.
    • Choose the port no for the web application.
    • Click on Enable Forms Based Authentication (FBA) Under Claims Authentication Types. Windows Authentication is enabled by default and if you dont need windows authentication then you need to remove the check the box.
    • Add the Membership Provider & Role Manager Name. I am using Membership Provider as "SQL-MembershipProvider" and Role Manager as "SQL-RoleManager". These names are case sensitive. 
  2. Modify the web.config file for Membership Provider and Role Manager:
    We need to modify 3 different web.config files for FBA to work. Web.config of FBA Web application, web.config of Central Administration Site & Web.config of STS. 
    • A. Modify web.config of FBA web application:
      Add connection string:
    • <connectionStrings>
      <add name="SQLConnectionString" connectionString="data source=SQL;Integrated Security=SSPI;Initial Catalog=SQL-Auth" />
      </connectionStrings>

      Add membership Provider and Role Manager:
      <roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false">
      <providers>
      <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <add connectionStringName="SQLConnectionString" applicationName="/" description="Stores and retrieves roles from SQL Server" name="SQL-RoleManager" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
      </roleManager>
      <membership defaultProvider="i">
      <providers>
      <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <add connectionStringName="SQLConnectionString" passwordAttemptWindow="5" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" description="Stores and Retrieves membership data from SQL Server" name="SQL-MembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
      </membership>
      </system.web>

    • Modify web.config of STS. You can locate the STS web.config from %programfiles%\common files\Microsoft Shared\web server extensions\14\WebServices\SecurityToken:
      Add connection string:
    • <connectionStrings>
      <add name="SQLConnectionString" connectionString="data source=SQL;Integrated Security=SSPI;Initial Catalog=SQL-Auth" />
      </connectionStrings>
      Add membership Provider and Role Manager:
      <roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false">
      <providers>
      <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <add connectionStringName="SQLConnectionString" applicationName="/" description="Stores and retrieves roles from SQL Server" name="SQL-RoleManager" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
      </roleManager>
      <membership defaultProvider="i">
      <providers>
      <add name="i" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <add connectionStringName="SQLConnectionString" passwordAttemptWindow="5" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" description="Stores and Retrieves membership data from SQL Server" name="SQL-MembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    • Modify web.config of the Central Administration web application:
      This modification is optional. You need it only if you want give Forms User authentication through central administration.
    • <connectionStrings>
      <add name="SQLConnectionString" connectionString="data source=SQL;Integrated Security=SSPI;Initial Catalog=SQL-Auth" />
      </connectionStrings>
      Add membership Provider and Role Manager:
      <roleManager defaultProvider="AspNetWindowsTokenRoleProvider" enabled="true" cacheRolesInCookie="false">
      <providers>
      <add connectionStringName="SQLConnectionString" applicationName="/" description="Stores and retrieves roles from SQL Server" name="SQL-RoleManager" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
      </roleManager>
      <membership defaultProvider="SQL-MembershipProvider">
      <providers>
      <add connectionStringName="SQLConnectionString" passwordAttemptWindow="5" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" description="Stores and Retrieves membership data from SQL Server" name="SQL-MembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
      </membership>\
    Notes:
    • You should set default providers:
      • Default providers are SPClaimsAuthRoleProvider and SPClaimsAuthMembershipProvider for FBA Site and STS.
      • Default providers are AspNetWindowsTokenRoleProvider and SQL-MembershipProvider for Central Administrator.
    •  If you failed to log-in after configuration check machine key in your web site and STS site are same, else check database connection string.
    • If you want to seaech for FBA users using wildcard, add the Membership and Role providers into the PeoplePickerWildcards section of the web.config:

    • <configuration>
          …
          <SharePoint>
              …
              <PeoplePickerWildcards>
                <clear />
                <add key="SQL-RoleManager" value="%" />
                <add key="SQL-MembershipProvider" value="%" />
              </PeoplePickerWildcards>
              …
          </SharePoint>
          …
      </configuration>
  1. Give permissions to users in SQL database:
    • Access Central Administration console and click on manage web applications under Application Management.
    • Select the web application and click on user Policy on ribbon.
    • Click on Add user and select Default Zone.
    • Now type the user name, add the user to the web application by defining appropriate permission.

Friday, April 20, 2012

Update vs. SystemUpdate for SharePoint List Item

When tried to Move List items from old Site to New Site. I am not only want to create items but also want to keep information of Created Date, Modified Date, Created User, or Modified User.

 I found item.Update() is not useful. It is not only changes that are made to the list item. It also updates the ModifiedBy, ModifiedOn, or version fields as per the current logged in user and current server time.

I used item.SystemUpdate() instead of item.Update(). This will help you in updating only those fields which are specified within your code blocks. It is allow me modify properties modified date and created user.