Wednesday, July 25, 2012

PeoplePicker Visual Webpart

<table>
<tr>
<td>
<SharePoint:PeopleEditor ID="PeoplePicker" runat="server" Width="300" MultiSelect="false"  BorderStyle="Solid" BorderColor="Black" BorderWidth="1" />
</td>
</tr>
<tr>
<td>
<SharePoint:PeopleEditor ID="PeopleEditor1" runat="server" Width="300" MultiSelect="True"  BorderStyle="Solid" BorderColor="Black" BorderWidth="1" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnDisplay" runat="server" Text="Display" OnClick="btnDisplay_Click"/>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbltext" runat="server"></asp:Label>
</td>
</tr>
</table>

protected void btnDisplay_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            for (int index = 0; index <= PeopleEditor1.ResolvedEntities.Count - 1; ++index)
            {

                PickerEntity objEntity = (PickerEntity)PeopleEditor1.ResolvedEntities[index];

                str += "SPUser" + objEntity.EntityData["SPUserID"] + " SPKEy" + objEntity.Key + "\n";

            }
            lbltext.Text = str;
            //Response.Write(str);


        }


Tuesday, July 24, 2012

Create InfoPath form in SharePoint 2010

Introduction

In the previous article, we learnt Create Content Sources in SharePoint 2010 using PowerShell.In this article we will be seeing how to create InfoPath form for SharePoint 2010 list.

Description:

I have created a custom list named “Custom” which has the following columns

For this list I am going to create an InfoPath form which will be used as New/Edit form in the list. New  form for the list looks like the following

Note: None of the columns is mandatory in Custom list

Create an InfoPath form:

1. Open Microsoft InfoPath Designer 2010.
2. Go to File =>New  => Click on SharePoint List from Available Form Templates

3. Data Connection Wizard will popup, enter the site URL.

4. Click on Next.
5. Select Customize an existing SharePoint list and then select Custom which is a custom list.

6. Click on Finish.

7. You could see the InfoPath form with the following columns

Publish the InfoPath form to SharePoint:

1. Go to File =>Info and then click on Quick Publish.

2. Publishing...

3. Form template is successfully published.

InfoPath form in SharePoint Edit or New form:

1. Open the SharePoint Site.
2. Go to Custom List and add a new item.
3. New form will be an InfoPath form as shown in the following.

How to use the Default SharePoint form:

1.  Go to List Settings.
2. In the General Settings, click on Form Settings.

3. You can select the Default SharePoint form or you can modify the existing InfoPath form.



Thanks for reading.

User Profile Imports using BCS

User Profile Service Application is used to synchronize the data from Active Directory to the SharePoint. User Profile data are maintained by Profile Database in SharePoint. Profile Database is used to stores and manages user’s information. In some scenarios you may require to get the data for the user profile from external system. Here you will see how to get the data for the user profile from SQL database using Business Data Connectivity services. Here I will be creating some custom user properties and map those user properties to the columns in the SQL database so that those user properties will get the values from the external system SQL database using BCS.

Introduction

User Profile Service Application is used to synchronize the data from Active Directory to the SharePoint. User Profile data are maintained by Profile Database in SharePoint. Profile Database is used to stores and manages user’s information. In some scenarios you may require to get the data for the user profile from external system. Here you will see how to get the data for the user profile from SQL database using Business Data Connectivity services. Here I will be creating some custom user properties and map those user properties to the columns in the SQL database so that those user properties will get the values from the external system SQL database using BCS.

SQL Server Database Details

I will be using SQL Server database as an external data source from where the data will be imported for the user profiles in SharePoint 2010. Database named “BCS Database” is created in SQL Server which contains the following tables.

      Figure :  BCS Database in SQL Server


EmployeeDetails table:

EmployeeDetails table contains the following columns

Figure :  EmployeeDetails table column names and data types
EmployeeDetails table contains the following rows

Figure :  EmployeeDetails table rows

Create New User Properties

1. Open Central Administration by going Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Central Administration.
2. Click on Manage Service Application which is available in Application Management section.

Figure: Application Management section in Central Administration
3. Click on User Profile Service Application.
4. Click on Manage User Properties in the People section.

Figure: Manage User properties in People section
5. Click on New Property.


Figure: New Property link

6. Enter the Name as EmpID, Display Name as EmpID and select integer from the Type dropdown as shown in Figure.

Figure: Enter the details for the new property EmpID
7. Click on Ok.
8. A new custom user property “EmpID” is created successfully and it will be available in Custom Properties section.
9. Create another custom property named “Designation”.
10. Click on New Property.
11. Enter the Name as Designation, Display Name as Designation and select string (Single Value) from the Type dropdown, as shown in Figure.
12. Enter the Length value as 50 because in the SQL EmployeeDetails table Designation column has a type nvarchar (50), as shown in Figure.

Figure: Enter the details for the new property Designation
13. In the Policy Settings, select Optional from the Policy Setting dropdown and select Everyone from Default Policy Setting dropdown, as shown in Figure.

Figure: Policy Settings for Designation property
14. Click on Ok.
15. A new custom user property “Designation” is created successfully and it will be available in Custom Properties section.

Configure Synchronization Connection

1. In the Central Administration, click on Manage Service Application which is available in Application Management section.
2. Click on User Profile Service Application.
3. Click on Configure Synchronization Connections in the Synchronization section.



Figure: Configure Synchronization Connections in Synchronization connection
4. Click on Create New Connection.

Figure: Create New Connection
5. Enter the Connection Name as BCS, select Business Connectivity Services from the Type dropdown and click on Select External Content Type button, as shown in Figure.

Figure: Create new synchronization connection
6. “External Content Type Picker – Webpage Dialog” will pop up, select the external content type “Employee Details ECT”.

Figure: External Content Type Picker
7. Click on Ok.
8. Select EmpID from the dropdown for connecting User Profile Store to Business Data Connectivity Entity as a 1:1 mapping, as shown in Figure.


Figure: Connect User Profile Store to Business Data Connectivity Entity as a 1:1 mapping
9. Click on Ok.
10. BCS synchronization connection is created successfully as shown in the Figure.



Figure: New synchronization connection BCS created

Add Mapping to User Property

1. In the Central Administration, click on Manage Service Application which is available in Application Management section.
2. Click on User Profile Service Application.
3. Click on Manage User Properties in the People section.
4. Select the Designation property in the Custom Properties section.
5. In the ECB menu, click on Edit.
6. In the Add New Mapping section, select BCS from the Source Data Connection dropdown, Designation from the Attribute dropdown and Import from the Direction dropdown, as shown in Figure.

Figure: Add Mapping to Designation user property
7. Click on Add.
8. New mapping is added to the Designation user property.
9. Click on Ok.

Edit the user profile

1. In the Central Administration, click on Manage Service Application which is available in Application Management section.
2. Click on User Profile Service Application.
3. Click on Manage User Profiles in the People section.


Figure: Manage User Profiles in People section
4. I am going to modify the User Profile “Vijai” whose EmpID is 100 in the SQL EmployeeDetails table.
5. Select the User Profile, in the ECB menu click on Edit User Profile.
6. Enter the EmpID value as 100.
7. Click on Save & Close.
8. Once the full synchronization is done for the User Profile “Vijai” the Designation property will have the value as “Associate” which will be imported from SQL EmployeeDetails table.

Start Full Synchronization

1. In the Central Administration, click on Manage Service Application which is available in Application Management section.
2. Click on User Profile Service Application.
3. Click on Manage User Profiles in the People section.

Figure: Start Profile Synchronization in Synchronization section
4. Select Start Full Synchronization option.

Figure: Start Full Synchronization
5. Click on Ok.
6. Once the Full Synchronization is doneEdit the User Profile and check.
7. Designation property will have the value imported from the SQL table as shown in the Figure.

Figure: Value for Designation user property imported from SQL database
Thus in this article we have seen how to import the data from external system like SQL database to SharePoint User Profiles using BCS.

Create Scopes in SharePoint 2010 using PowerShell

Introduction

In the previous article, we learnt Create InfoPath form in SharePoint 2010 .In this article we will be seeing how to create Scopes in SharePoint 2010 Enterprise Search Service Application using PowerShell

Automating the Scopes creation in SharePoint 2010

We can create Scopes in SharePoint 2010 Enterprise Search Service Application from Central Administration.
Go to Central Administration => Application Management => Manage Service Applications => Enterprise Search Service Application.

On the Quick Launch Menu, go to Queries and Results then click on Scopes.
You could be able to see the Scopes. By clicking on New Scope link we can create a new Scope.
Another way is we can create the Scopes in Search Service Application using SharePoint Object Model.
Here we will be seeing about automating the Scopes creation using powershell script.

Steps Involved:

1. Create the input xml file which contains the inputs for Scope creation.
2. Create ps1 file which contains the script for scope creation.

CreateScopes.xml

 

<?xml version="1.0" encoding="utf-8" ?>
<Scopes>
<
SSAName>EnterPrise Search Service Application</SSAName> <Scope Name="Sample1" Description="Sample1 Scope" /> <Scope Name="Sample2" Description="Sample2 Scope" /> <Scope Name="Sample3" Description="Sample3 Scope" />
</Scopes>

CreateScopes.ps1


 #----------------Get the xml file---------------------------------------------------------------

 [xml]$xmlData=Get-Content "C:\Users\Desktop\ContentSources\CreateScopes.xml"


 #----------------Create New Scope function---------------------------------------------

Function CreateNewScope()
{
 $ssa=Get-SPEnterPriseSearchServiceApplication -Identity $xmlData.SSAName
$scopeCollection=Get-SPEnterpriseSearchQueryScope -SearchApplication $ssa
$xmlData.Scopes.Scope | ForEach-{ 
Object {
$newScopeName=$_.Name $newScopeDescription=$_.Description $scope=Get-SPEnterpriseSearchQueryScope -Identity $newScopeName -SearchApplication $ssa
if($scope -eq $null) {
write-host -f Magenta Creating scope $_.scope New-SPEnterpriseSearchQueryScope -Name $newScopeName
-Description $newScopeDescription -SearchApplication $ssa -DisplayInAdminUI $
true write-host -f Green $newscope.Name is created successfully
}else {
write-host -f yellow $newScopeName scope already exists write-host -f yellow Deleting $newScopeName scope Remove-SPEnterpriseSearchQueryScope -Identity $newScopeName  
-SearchApplication $ssa -confirm:0
write-host -f green $newScopeName scope
is deleted successfully write-host -f Magenta Creating $newScopeName scope New-SPEnterpriseSearchQueryScope -Name $newScopeName  
-Description $newScopeDescription -SearchApplication $ssa -DisplayInAdminUI $true
write-host -f green $newScopeName scope is successfully created
}
}
}


#----------------Calling the function---------------------------------------------

CreateNewScope

Run the Script:

1. Go to Start.
2. Click on All Programs.
3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell.
4. Run the C:\Users\Desktop\ContentSources\CreateScopes.ps1

Output:


And in the Central Administration you could see the newly added Scopes as shown in the following

Thanks for reading.

Customize SharePoint List Forms using InfoPath 2010

Introduction

In the previous article, we learnt Create Scopes in SharePoint 2010 using PowerShell.In this article we will be seeing how to customize SharePoint List Forms using InfoPath Forms.

Description:

I have a custom List named Employee Details which contains the following columns.

Here I am going to customize the list forms using InfoPath 2010 and the form looks like the following

Customize SharePoint List Form:

1. Go to Employee Details list.
2. On the ribbon interface, click on List Tools and then click on List tab.
3. Click on Customize Form which is available in Customize List ribbon group.



4. InfoPath form will be opened.
5. Select all content in the form by pressing CTRL+A.
6. Press Delete to delete all the content in the form.

Create Custom Layout:

1. On the Page Design tab, click Page Layout Templates, and then click Color Bar as shown in the following


2. The layout looks like the following


3. Select the layout table, and then click the Center button on the Home tab of the ribbon.
4. Click on Add tables placeholder text.
5. On the Insert tab, click on Two – Column 2 table as shown in the following

6. Add one more Two – Column 2 table.
7. The layout looks like the following


Add a header image to the form:

1. Click on “Click to add title” placeholder text.
2. On the Insert menu, click on Picture.


3. Browse for the picture and then click on Insert.
4. Add the text Employee Details and change the Shading color.
5. Title looks like the following

Insert the fields in the custom layout:

1. From the Fields task pane, Drag and drop the fields to the form. You should highlight both columns when you release the mouse so that the label for the control will appear automatically in the left column.

2. Customized form looks like the following

3. On the Home tab, click on Preview.

4. The form looks like the following


Publish the InfoPath form to SharePoint:

1. Go to File => Info and then click on Quick Publish.

2. Publishing...

3. Form template is successfully published.

InfoPath form in SharePoint Edit or New form:

1. Open the SharePoint Site.
2. Go to Employee Details list and add a new item.
3. New form will be an InfoPath form as shown in the following.

Hope you liked this article, stay tuned for next article in this article series.
Thanks for reading.