You are here: Ektron Namespace > .NET Assemblies > Ektron.Cms.API Namespace > Ektron.Cms.API.User Namespace > Classes > User Class > User Methods > GetUserByUsername
Ektron CMS400.NET API Documentation
ContentsIndexHome
PreviousUpNext
User.GetUserByUsername Method

Loads the user details for the given user.

C#
public UserData GetUserByUsername(String username);
Visual Basic
Public Function GetUserByUsername(ByVal username As String) As UserData
Parameters 
Description 
username 
The username. 

Ektron.Cms.UserData

The following example shows how to create a Web page that retrieves user details for a given username. This example uses some standard drag and drop controls and a small section of VB code utilizing the GetUserByUsername method. This method uses the InternalAdmin to retrieve the user details. In the first section, we will deal with the standard drag and drop controls. In the second, we'll deal with the code behind. 

 

  1. Between the form tags, add a label to show where to enter a username.
       <asp:Label ID="Label1" runat="server" Text="Username: "></asp:Label>
  2. Add a text box to enter the username.
       <asp:TextBox ID="txtUserName" runat="server" Width="63px"></asp:TextBox>
  3. add a RequiredFieldValidator control from the Validation control menu. This validates that something appears in the username box.
       <asp:RequiredFieldValidator ID="rfvUserId" runat="server" ControlToValidate="txtUserName"
           ErrorMessage="Please enter Username"></asp:RequiredFieldValidator>
  4. Add two breaks for spacing purposes.
      <br /><br />
  5. Add a button to submit the username.
      <asp:Button ID="btnGetUser" runat="server" Text="Get Custom Properties" Width="148px" />
  6. Add two more breaks for spacing purposes.
      <br /><br />
  7. Add a label to display the given user's details.
      <asp:Label ID="lblResult" runat="server"></asp:Label>

 

Add the following information to the code behind of your aspx.vb page.

  1. Add button click event.

        Protected Sub btnGetUser_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetUser.Click

  1. Create an object for the user API.

            Dim userAPI As New Ektron.Cms.API.User.User

  1. Create an object for the user data.

            Dim userObj As Ektron.Cms.UserData

  1. Create a Try/Catch around the GetUserByUsername method. This allows you to catch any exceptions and helps when debugging.

            Try
                userObj = userAPI.GetUserByUsername(txtUserName.Text.Trim)

  1. Check to make sure the a user ID exists.

                If userObj.Id = 0 Then
                   lblResult.Text = "Invalid Username"
                   Exit Sub
                End If

  1. Create an integer place holder.

                Dim i As Integer

  1. Check to make sure the attribute list is populated.

                If Not userObj.AttributeList Is Nothing Then

  1. If the list is populated, display the results.

                   lblResult.Text = "<table> <th>Name</th> <th>Value</th> <th>Type</th>"
                   For i = 0 To userObj.AttributeList.Length - 1 Step 1
                       lblResult.Text &= "<tr>"
                       lblResult.Text &= "<td>" & userObj.AttributeList(i).Name & "</td>"
                       lblResult.Text &= "<td>" & userObj.AttributeList(i).Value & "</td>"
                       lblResult.Text &= "<td>" & userObj.AttributeList(i).ValueType.ToString() & "</td>"
                       lblResult.Text &= "</tr>"
                   Next
                   lblResult.Text &= "</table>"

  1. If nothing is contained in the list, display a message.

                Else
                   lblResult.Text &= "No custom properties set-up for this user"
               End If

  1. If there is an error, let the user know what happened.

            Catch ex As Exception
               lblResult.Text = ex.Message
            End Try 
        End Sub
Created with a commercial version of Doc-O-Matic. In order to make this message disappear you need to register this software. If you have problems registering this software please contact us at [email protected].
Copyright (c) 2008. All rights reserved.
What do you think about this topic? Send feedback!