ITguy451
Guest
|
Posted:
Thu Feb 03, 2005 10:45 pm Post subject:
Retrieving user info doesn't work |
|
|
The following code compiles fine, but when I add the webpart it
displays a web page that says the "EmployeeProjects" web part appears
to be causing a problem. I can go to the maintenance page and remove it
and my site page comes up again. This is a web part being added to "My
Site" using SharePoint Portal Server 2003 with Sp1 applied. All I want
to do is retrieve the user so I can call a SQL db and retrieve the
projects assigned to the user - I have this in a stores procedure so I
think once the user name can be retrieved, I'll be all set. Thanks for
the help!
Code:
string _userName = "";
Microsoft.SharePoint.Portal.PortalContext portalContext =
Microsoft.SharePoint.Portal.PortalApplication.GetContext();
if(portalContext != null)
{
//running a portal application
try
{
ProfileLoader profileLoader = ProfileLoader.GetProfileLoader();
UserProfile userProfile = profileLoader.GetUserProfile();
_userName = userProfile["PreferredName"].ToString();
}
catch(System.Exception e)
{
output.Write(e.Message);
}
}
else
{
try
{
//running in WSS application
SPWeb thisWeb = SPControl.GetContextWeb(Context);
SPUser currentUser = thisWeb.CurrentUser;
_userName = currentUser.Name;
}
catch(System.Exception e)
{
output.Write(e.Message);
}
}
output.Write(SPEncode.HtmlEncode(_userName)); |
|