To demonstrate this scenario, I will retrieve user profiles and store it into GridView.
Here is my .aspx code
- <table style="width: 900px; padding: 20px;">
- <tr>
- <td>Find profiles :</td>
- <td>
- <asp:TextBox runat="server" ID="txtUserID"></asp:TextBox>
- <asp:Button runat="server" ID="btnSearch" Text="Find" OnClick="FindUserProfile" />
- </td>
- </tr>
- </table>
- <div id="divUserProfilesGrid" runat="server">
- <hr />
- <p>Following user profiles are found by this search :</p>
- <br />
- <div style="height: auto;overflow-y: auto;max-height:215px">
- <asp:GridView ID="grdUserProf" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">
- <AlternatingRowStyle BackColor="White" />
- <EditRowStyle BackColor="#2461BF" />
- <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
- <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
- <RowStyle BackColor="#EFF3FB" />
- <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
- <SortedAscendingCellStyle BackColor="#F5F7FB" />
- <SortedAscendingHeaderStyle BackColor="#6D95E1" />
- <SortedDescendingCellStyle BackColor="#E9EBEF" />
- <SortedDescendingHeaderStyle BackColor="#4870BE" />
- </asp:GridView>
- </div>
- <hr />
- </div>
For this scenario we need to add references to assembly.
- using Microsoft.SharePoint;
- using Microsoft.Office.Server;
- using Microsoft.Office.Server.UserProfiles;
On the click of Find button we are executing following code.
- SPServiceContext serviceContext1 = SPServiceContext.GetContext(SiteUrl);
- UserProfileManager upm = new UserProfileManager(serviceContext1);


Join the conversation! Your thoughts help the community grow.