views:

918

answers:

5

Is there somthing in the dotnetnuke framework which will allow me to pass it a userId and it would return the UserInfo object filled with details of that userId.

If not what would be the normal way of doing this?

+2  A: 

I believe that DotNetNuke.Entities.Users.UserController has a method (GetUser) that will do that, if you also have a portal ID. Users can be shared across portals, so it's (apparently) necessary to know the portal for which you're requesting the user information before they can properly fill the UserInfo object.

If you only have a user ID and no portal ID, I'd first suggest that you see if you can get a portal ID, too. If not, you'll need to go to the database to get what you need. Ideally, you'll be in there as little as you can be (since the database isn't a guaranteed API). So, if you just do a quick query to get a portal ID for the user:

SELECT PortalID From {databaseOwner}{objectQualifier}UserPortals WHERE UserID = @userId

You can then use UserController.GetUser to retrieve what you need.

bdukes
A: 

If you need to get the current user it's simpler:

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo

Just a note.

codemypantsoff
A: 

It's not return User ID what is the problem

Dim nowUser As UserInfo = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo
response.write(nowUser)
uttam
A: 

Try this (in DNN 5.x with C#)

private UserInfo _currentUser =
                   DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

Then use the UserInfo later...

int UserID = _currentUser.UserID
A: 

I used the way posted by bdukes with one modification: PortalId can be get from PortalSettings:

DotNetNuke.Entities.Users.UserInfo user = DotNetNuke.Entities.Users.UserController.GetUser(PortalSettings.PortalId, user_id, true);
Nico