Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Displaying Login Name in Web Parts

  Asked By: Allan    Date: Aug 21    Category: Sharepoint    Views: 3525

Does anyone know how to retrieve the users details into a web part.
I would like to get details like display name, email and server
details like DOMAIN\USER NAME.

Does anyone know. Please help.

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Lionel Phelps     Answered On: Aug 21

I would suggest using Request.ServerVariables("Logon_User") and from there you could query the Active Directory and find out more of their information.

 
Answer #2    Answered By: Marlon Colon     Answered On: Aug 21

Is there any way of doing it using Microsoft.SharePoint.SPUser??

 
Answer #3    Answered By: Pierre Copeland     Answered On: Aug 21

You can use SPUser class to retrieve  all users  for the site. The details
can be found from Sharepoin SDK. I am attaching portion of this which
help you in this regard.


SPUser Class

The SPUser class represents a user in Microsoft Windows SharePoint
Services.


System.Object

Microsoft.SharePoint.SPMember

Microsoft.SharePoint.SPUser

[Visual Basic]Public Class SPUser
Inherits Microsoft.SharePoint.SPMember
[C#]public class SPUser : Microsoft.SharePoint.SPMember
Public Methods
The following table shows the public methods of the SPUser class and a
brief description of each.

Name Description
ToString Returns the user name  of the user.
Update Updates the database with changes made to the properties of the
user object.

Public Properties
The following table shows the public properties of the SPUser class, the
data type of each property, and a brief description of each.

Name Data Type Description
Alerts Microsoft.SharePoint.SPAlertCollection Gets the collection of
alerts for the user.
Email String Gets or sets the e-mail address of the user.
Groups Microsoft.SharePoint.SPGroupCollection Gets the collection of
cross-site groups of which the user is a member.
ID Int32 Gets the member ID for the user.
IsDomainGroup Boolean Gets a Boolean value that indicates whether the
user is a domain group.
IsSiteAdmin Boolean Gets or sets a Boolean value that specifies whether
the user is a site collection administrator.
LoginName String Gets the user name of the user.
Name String Gets or sets the display  name of the user.
Notes String Gets or sets notes for the user.
OwnedGroups Microsoft.SharePoint.SPGroupCollection Gets the collection
of cross-site groups of which the user is an owner.
ParentWeb Microsoft.SharePoint.SPWeb Gets the parent site for the user.
Roles Microsoft.SharePoint.SPRoleCollection Gets the collection of site
groups of which the user is a member.
Sid String Gets the unique security ID for the network account of the
user.
Xml String Gets the XML representation of the user object.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are safe
for multithreaded operations. Instance members are not guaranteed to be
thread safe.

Remarks

Use the AllUsers or SiteUsers property of the SPWeb class, the
GetAllAuthenticatedUsers method of the SPUtility class, or the
GetUniqueUsers method of the SPAlertCollection class, to return all the
users of a site, all the users in the site collection, all the
authenticated users of a site, or a list of users for a collection of
alerts. Otherwise, use the Users property of the SPGroup, SPRole, or
SPWeb class to return the users in a cross-site group, site group, or
site. Use an indexer to return a single user from the collection. For
example, if the collection is assigned to a variable named myUsers, use
myUsers[index] in C#, or myUsers(index) in Visual Basic .NET, where
index is either the index number of the user in the collection or the
user name of the user.

Every user has a unique member ID, has the permissions associated with
that membership, and can be represented by an SPMember object. The
following example assigns a user to an SPMember object:

SPMember myMember = site.Users["User_Name"];

For general information about users and security, see Security, Users,
and Groups Overview.


Example

The following code example modifies the e-mail address, display name,
and notes for a specified user object.

[Visual Basic .NET]Dim siteCollection As SPSite =
SPControl.GetContextSite(Context)
Dim site As SPWeb = siteCollection.AllWebs("Site_Name")
Dim user As SPUser = site.AllUsers("User_Name")

user.Email = "E-mail_Address"
user.Name = "Display_Name"
user.Notes = "User_Notes"

user.Update()
[C#]SPSite siteCollection = SPControl.GetContextSite(Context);
SPWeb site = siteCollection.AllWebs["Site_Name"];
SPUser user = site.AllUsers["User_Name"];

user.Email = "E-mail_Address";
user.Name = "Display_Name";
user.Notes = "User_Notes";

user.Update();
This example requires using directives (Imports in Visual Basic) for
both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls
namespaces.


Requirements
Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security

 
Answer #4    Answered By: Lewis Mann     Answered On: Aug 21

When i am trying to add the "Asp" method((<%=request.servervariables
("logon_user")%>)) of getting the userLogin name  into the
default.aspx code, it shouts with an error.

Paresh, can you extend some more help, to make your template work
from a .aspx page.

 
Answer #5    Answered By: Clayton Berry     Answered On: Aug 21

Have you tried doing following

User.Identity.Name

 
Answer #6    Answered By: Larry Gonzales     Answered On: Aug 21

still i am getting these two errors:

===================
Error:
An unexpected error has occurred.

web parts  maintenance page:If you have permission, you can use this
page to temporarily disable web  parts or remove personal settings.For
more information, contact your site administrator.
=================
Error:
External component has thrown an exception.
==================
Now, i want to know is there any way to mixup my asp code in
the .aspx page.

 
Answer #7    Answered By: Lamont Tran     Answered On: Aug 21

No way, I don't think so you can do that. You have to
remove the asp code from the sps sites page.

 
Didn't find what you were looking for? Find more on Displaying Login Name in Web Parts Or get search suggestion and latest updates.




Tagged: