Friday, 24 February 2012

How to Update People Picker column users in SharePoint List

Use below code to update people picker column users in sharepoint list

SPUser user=web.EnsureUser("loginname");
mylistlitem["Assigned To"]=user;

Friday, 17 February 2012

Advanced Search(Manage Metadata column in SharePoint Library)

Create Column in SharePoint Document library in the name of  "Employees" and column type as 'Metadata'

Terms and Term Sets in SharePoint

Managed Metadata

Managed metadata is a hierarchical collection of centrally managed terms that you can define, and then use as attributes for items in Microsoft SharePoint Server 2010. - MSDN (http://msdn.microsoft.com/en-us/library/ee559337.aspx). The terms that are created can be used to tag content in SharePoint making it easier to search for items or categorize and filter them. In SharePoint 2010, the hierarchy starts with the Managed Metadata Term Store and is organized by Groups which contain TermSets which in turn contain Terms that can also contain other Terms. The image below is a sample to demonstrate this organization.
Image1.PNG

Creating Taxonomy Terms and TermSet

To create Managed Metadata through the UI in SharePoint 2010, you use the Term Store Management Tool, which can be accessed either from the Managed Metadata Service in the Central Administration site:
Image2.PNG
or from the Term store management link on the Site Settings page of a Site:
Image3.PNG
Once in the management tool, to add a new Managed Metadata group, hover over the end of the Managed Metadata Service item to expose an arrow and click to expand the menu then click the New Group menu item.
Image4.PNG
After the group has been added, you will see on the right side of the screen several areas that can be used to designate managers and contributors for the Group. Since these setting are similar to other types of configuration in SharePoint, I won't discuss it here and continue to concentrate on the creation of the Term Sets and Terms.
After the Group has been created, you can use the menu on it to create a Term Set.
Image5.PNG
We'll skip the Import Term Set item for the moment and just create a New Term Set. Once again, after the Term Set has been created, you will see the different settings that can be applied to it on the right.
Using the menu once again on the Term Set, there are a few more options that are available at the Term Set level.
Image6.PNG


upload as .csv file format


<PropertyDefs>       
<PropertyDef Name="Path" DataType="text" DisplayName="URL"/>       
<PropertyDef Name="Size" DataType="integer" DisplayName="Size (bytes)"/>       
<PropertyDef Name="Write" DataType="datetime" DisplayName="Last Modified Date"/>       
<PropertyDef Name="FileName" DataType="text" DisplayName="Name"/>       
<PropertyDef Name="Description" DataType="text" DisplayName="Description"/>       
<PropertyDef Name="Title" DataType="text" DisplayName="Title"/>       
<PropertyDef Name="Author" DataType="text" DisplayName="Author"/>       
<PropertyDef Name="DocSubject" DataType="text" DisplayName="Subject"/>       
<PropertyDef Name="DocKeywords" DataType="text" DisplayName="Keywords"/>       
<PropertyDef Name="DocComments" DataType="text" DisplayName="Comments"/>       
<PropertyDef Name="CreatedBy" DataType="text" DisplayName="Created By"/>       
<PropertyDef Name="ModifiedBy" DataType="text" DisplayName="Last Modified By"/>
<PropertyDef Name="Employees" DataType="text" DisplayName="Employees"/>  

<ResultTypes>       
<ResultType DisplayName="All Results" Name="default">           
<KeywordQuery/>          
<PropertyRef Name="Author" />           
<PropertyRef Name="Description" />           
<PropertyRef Name="FileName" />           
<PropertyRef Name="Size" />           
<PropertyRef Name="Path" />           
<PropertyRef Name="Write" />           
<PropertyRef Name="CreatedBy" />           
<PropertyRef Name="ModifiedBy" />
<PropertyRef Name="Employees" /> 
</ResultType>       


Need to Map Employees(Managed Metadata) column with the above Property Employees(Advanced Search property)



Now we can able to search datas based on Items in the Employees column

Thursday, 16 February 2012

Form Based Authentication in SharePoint 2010

Form Based Authentication

we need to change three web.config values
1)Central Admin
2)STS Web.Config
3)Clams Web application Web.Config

Create a new web application
  • Go to Central Administration
  • Go to Application Management
  • Click on Manage Web Applications
  • Click New
  • Select Claims Based Authentication
  • Identity Providers
         * Check the Enable Windows Authentication box or you won’t be able to crawl the site
         * Check the Enable ASP.NET Membership and Role Provider checkbox
              * In the Membership provider name edit box, type SqlMember
              * In the Role provider name edit box, type SqlRole
  • Create a new site collection
    • Go to Central Administration
    • Go to Application Management
    • Click Create site collections
    • Select the newly created web application
    • Fill in a name and select a template
               Configure the Membership Provider and Role Manager.
  • On SharePoint 2010 server open the command prompt.
  • Navigate to C:\Windows\Micrsooft .Net\Framework64\v2.0.50727
  • Run “aspnet_regsql.exe”. This will open ASP .Net SQL Server Setup wizard. On this click on NEXT.

  • Click on “Configure SQL Server for Application Services”.

  • Specify the Database name. If you don’t specify the database name then it will create a database call aspnetdb



    • Adjust the web.config of the Central Administration site
      • Open the Central Administration site's web.config file
      • Find the </configSections> entry
      • Paste the following XML directly below it
      <connectionStrings>
         <clear />
         <add name="AspNetSqlMembershipProvider"
       connectionString="data source=sql.sharepoint.com;Integrated Security=SSPI;Initial Catalog=aspnetdb" 
       providerName="System.Data.SqlClient" />
      </connectionStrings>
      • Find the <system.web> entry
      • Paste the following XML directly below it
      <roleManager enabled="true" 
         cacheRolesInCookie="false" 
         cookieName=".ASPXROLES" 
         cookieTimeout="30" 
         cookiePath="/" 
         cookieRequireSSL="false" 
         cookieSlidingExpiration="true" 
         cookieProtection="All" 
         defaultProvider="AspNetWindowsTokenRoleProvider" 
         createPersistentCookie="false" 
         maxCachedResults="25">
         <providers>
            <clear />
            <add connectionStringName="AspNetSqlMembershipProvider" 
               applicationName="/" 
               name="SqlRole" 
               type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,
       Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            <add applicationName="/" 
               name="AspNetWindowsTokenRoleProvider" 
               type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0,
       Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
         </providers>
      </roleManager>
      
      <membership defaultProvider="SqlMember" 
         userIsOnlineTimeWindow="15" hashAlgorithmType="">
         <providers>
            <clear />
            <add connectionStringName="AspNetSqlMembershipProvider" 
               enablePasswordRetrieval="false" 
               enablePasswordReset="true" 
               requiresQuestionAndAnswer="true" 
               passwordAttemptWindow="10" 
               applicationName="/" 
               requiresUniqueEmail="false" 
               passwordFormat="Hashed" 
               name="SqlMember" 
               type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0,
       Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
         </providers>
      </membership>
      • Double check whether the <membership> and <rolemanager> entries only exist ones. Delete any double entries.
      • Paste the following XML below the <PeoplePickerWildcards> entry
      <clear />
      <add key="AspNetSqlMembershipProvider" value="%" />
      <add key="SqlMember" value="%"/>
      <add key="SqlRole" value="%"/>
      Adjust the web.config of the Security Token Service (STS) virtual directory NB: you will need to make the changes to the Security Token Service virtual directory on each server hosting either Central Administration or the claims based web application
      • Open the Security Token Service (STS) virtual directory's web.config file
      • Find the </system.net> entry
      • Paste the following XML directly below it
      <connectionStrings>
         <clear />
         <add name="AspNetSqlMembershipProvider"
       connectionString="data source=sql.sharepoint.com;Integrated Security=SSPI;Initial Catalog=aspnetdb" 
       providerName="System.Data.SqlClient" />
      </connectionStrings>
      • Add a <system.web> entry directly below the </connectionStrings>
      • Paste the following XML directly below the <system.web> entry
      <membership>
         <providers>
           <add connectionStringName="AspNetSqlMembershipProvider" 
              enablePasswordRetrieval="false" 
              enablePasswordReset="true" 
              requiresQuestionAndAnswer="true" 
              passwordAttemptWindow="10" 
              applicationName="/" 
              requiresUniqueEmail="false" 
              passwordFormat="Hashed" 
              name="SqlMember" 
              type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
         </providers>
      </membership>
      
      <roleManager enabled="true">
         <providers>
            <add connectionStringName="AspNetSqlMembershipProvider"
               applicationName="/" 
               name="SqlRole" 
               type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
         </providers>
      </roleManager>
      • Add a </system.web> entry directly below it
      Adjust the web.config of the claims based web application
      • Open the claims based web application's web.config file
      • Find the </configSections> entry
      • Paste the following XML directly below it
      <connectionStrings>
         <clear />
         <add name="AspNetSqlMembershipProvider"
       connectionString="data source=sql.sharepoint.com;Integrated Security=SSPI;Initial Catalog=aspnetdb" 
       providerName="System.Data.SqlClient" />
      </connectionStrings>
      • Locate the <membership> entry
      • Replace everything from <membership> to </membership> with the following XML
      <membership defaultProvider="i" 
         userIsOnlineTimeWindow="15" 
         hashAlgorithmType=""> 
         <providers> 
            <clear /> 
            <add connectionStringName="AspNetSqlMemberShipProvider" 
               enablePasswordRetrieval="false" 
               enablePasswordReset="true" 
               requiresQuestionAndAnswer="true" 
               passwordAttemptWindow="10" 
               applicationName="/" 
               requiresUniqueEmail="false" 
               passwordFormat="Hashed" 
               name="SqlMember" 
               type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
           <add name="i" 
              type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, 
      Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> 
         </providers> 
      </membership>
      • Locate the <roleManager> entry
      • Replace everything from <roleManager> to </roleManager> with the following XML:
      <roleManager enabled="true" 
         cacheRolesInCookie="false" 
         cookieName=".ASPXROLES" 
         cookieTimeout="30" 
         cookiePath="/" 
         cookieRequireSSL="false" 
         cookieSlidingExpiration="true" 
         cookieProtection="All" 
         defaultProvider="c" 
         createPersistentCookie="false" 
         maxCachedResults="25"> 
            <providers> 
               <clear /> 
               <add connectionStringName="AspNetSqlMemberShipProvider" 
                  applicationName="/" 
                  name="AspNetSqlRoleProvider" 
                  type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
               <add applicationName="/" 
                  name="SqlRole" 
                  type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, 
      Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
               <add name="c" type="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, 
      Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> 
         </providers> 
      </roleManager> 
      • Paste the following XML below the PeoplePickerWildcards entry
      <clear />
      <add key="AspNetSqlMembershipProvider" value="%" />
      <add key="SqlMember" value="%"/>
      <add key="SqlRole" value="%"/>
      Add a user policy to the web application
      • Go to Central Administration
      • Go to Application Management
      • Click on Manage Web Applications
      • Select the claims based web application
      • Click on User Policy
      • Click on the Add Users link
      • Click the Next button.
      • Click the Address Book icon.
      • Type in the NT login name or account name and click the search button. If it’s working correctly you should see at least two entries for the account – one that is for the user’s Active Directory account, and one that is for that same account but which was found using the LDAP provider.
      • Select the account in the User section and click the Add button
      • Click the OK button
      • Check the Full Control checkbox, then click the Finish button
        Add Users in SQL(need to run the following Query)

    declare @now datetime
     set
      @now= GETDATE()

    exec aspnet_Membership_CreateUser '/','sureshec47','Lakshmi47',
    '','rsuresh@kotecso.com','','',1,@now,@now,0,0,null


    EXEC
      aspnet_Roles_CreateRole '/', 'Admin'

    EXEC aspnet_UsersInRoles_AddUsersToRoles '/', 'sureshec47', 'Admin', 8


    we will get the users in the SP Central Admin like the following fig
     


    Wednesday, 1 February 2012

    Submit multiple infopath forms to mutiple form libraries through coding

    FileSubmitConnection fc = (FileSubmitConnection)this.DataConnections["Main submit"];
    SPContext ctx = SPContext.Current;
    string ss = ctx.Web.Url;

    fc.FolderUrl = ss + "/" + "Form Library Name";
    fc.Execute();