Ektron CMS400.NET API Documentation
|
Loads the user details for the given user.
public UserData GetUserByUsername(String username);
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.
Protected Sub btnGetUser_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetUser.Click
Dim userAPI As New Ektron.Cms.API.User.User
Dim userObj As Ektron.Cms.UserData
Try
userObj = userAPI.GetUserByUsername(txtUserName.Text.Trim)
If userObj.Id = 0 Then lblResult.Text = "Invalid Username" Exit Sub End If
Dim i As Integer
If Not userObj.AttributeList Is Nothing Then
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>"
Else lblResult.Text &= "No custom properties set-up for this user" End If
Catch ex As Exception lblResult.Text = ex.Message End Try End Sub
Copyright (c) 2008. All rights reserved.
|
What do you think about this topic? Send feedback!
|