The best way to do this is modified by personal self. Using user Id, I can get all information of user and then construct a user box just like in directory module. Below are some code demonstrate my work, hope they can be helped.
//Get current loged user id
public int GetUserId()
{
try
{
UserInfo _currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
return _currentUser.UserID;
}
catch
{
return -1;
}
}
//Get all user roles base on user name
public string[] GetUserRoles(string userName)
{
try
{
return Roles.GetRolesForUser(userName);
}
catch
{
return null;
}
}
//Detect current loged user's role
public string DetectDNNUser()
{
var userInfo = UserController.GetCurrentUserInfo();
if (userInfo.IsInRole("Administrators"))
{
return "Administrators";
}
else if (userInfo.IsInRole("Admin Group"))
{
return "Admin Group";
}
return "";
}
//Get user info base on user id
public UserInfo GetUserInfo(int userId)
{
PortalSettings portalSettings = new PortalSettings();
int portalId = portalSettings.PortalId;
DotNetNuke.Entities.Users.UserController oUserController = new DotNetNuke.Entities.Users.UserController();
UserInfo userInfo = oUserController.GetUser(portalId, userId);
return userInfo;
}
Besides there is an easy way to do this, that is link user name to the ActiveFeed page. All user information and control goes here.
Eg: <a href='http://" + GetDefaultPortalAlias() + "/ActivityFeed/tabid/" + 60 + "/userId/" + UserId + "'>username</a>
//Get default Portal Allias
public string GetDefaultPortalAlias()
{
try
{
PortalSettings portalSettings = new PortalSettings();
int portalId = portalSettings.PortalId;
string defaultPortalAlias = portalSettings.DefaultPortalAlias;
return defaultPortalAlias;
}
catch
{
return null;
}
}
//Get current tab name by tab id
public string GetCurrentTabName(int tabId)
{
DotNetNuke.Entities.Tabs.TabController tabController = new DotNetNuke.Entities.Tabs.TabController();
DotNetNuke.Entities.Tabs.TabInfo tabInfo = tabController.GetTab(tabId);
string tabName = tabInfo.TabName;
return tabName;
}
//Get current tab id by tabname
public int GetCurrentTabId(string tabName)
{
int PageTabId = 0;
DotNetNuke.Entities.Tabs.TabInfo objTab = default(DotNetNuke.Entities.Tabs.TabInfo);
DotNetNuke.Entities.Tabs.TabController objTabs = default(DotNetNuke.Entities.Tabs.TabController);
objTab = objTabs.GetTabByName(tabName, GetDefaultPortalId());
PageTabId = objTab.TabID;
return PageTabId;
}
Best Regards,
Dung Tri