Retrieving user info doesn't work
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Retrieving user info doesn't work

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
ITguy451
Guest





Posted: Thu Feb 03, 2005 10:45 pm    Post subject: Retrieving user info doesn't work Reply with quote

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));
Back to top
stevekay72



Joined: 01 Mar 2006
Posts: 1

Posted: Wed Mar 01, 2006 11:26 am    Post subject: Reply with quote

If you amend the following line to include the portal context:

Code:
ProfileLoader profileLoader = ProfileLoader.GetProfileLoader( portalContext );


It may help (it worked for me anyway!!)
Back to top
View user's profile Send private message MSN Messenger
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB