Hello!!

I have a Web part and I show some info in this web part.
The information that I want to show in the web part change
depending what user is conected to sharepoint (V2.0). Is
there a way to detect in the web part what user is logged
in sharepoint?

Thanks in advance

Maria Teresa

Re: Detect a a user by James

James
Mon Oct 27 13:24:44 CST 2003

Sure. Basically you want to create an instance of the SPWeb object and then
get the CurrentUser property (if no name is defined in the user profile for
the user, the Name property will be NULL, in that case you would want to get
the LogonName, which is the DOMAIN\UserName):

SPWeb myWeb = SPControl.GetContextWeb(Context);

SPUser currentUser = myWeb.CurrentUser;

if (currentUser.Name != "")

username = currentUser.Name;

else

username = currentUser.LoginName;

HTH


--
James Edelen
Microsoft MVP - SharePoint Portal Server
Microsoft MVP - Windows XP Media Center
Microsoft Associate Expert
Expert Zone - http://www.microsoft.com/windowsxp/expertzone
"Maria Teresa" <maria.petrullo@eniac.com> wrote in message
news:020101c39cb8$79071a50$a301280a@phx.gbl...
> Hello!!
>
> I have a Web part and I show some info in this web part.
> The information that I want to show in the web part change
> depending what user is conected to sharepoint (V2.0). Is
> there a way to detect in the web part what user is logged
> in sharepoint?
>
> Thanks in advance
>
> Maria Teresa



Re: Detect a a user by Maria

Maria
Tue Oct 28 06:59:01 CST 2003

Hello!!!

Thanks a lot for your help!!!
>-----Original Message-----
>Sure. Basically you want to create an instance of the
SPWeb object and then
>get the CurrentUser property (if no name is defined in
the user profile for
>the user, the Name property will be NULL, in that case
you would want to get
>the LogonName, which is the DOMAIN\UserName):
>
>SPWeb myWeb = SPControl.GetContextWeb(Context);
>
>SPUser currentUser = myWeb.CurrentUser;
>
>if (currentUser.Name != "")
>
>username = currentUser.Name;
>
>else
>
>username = currentUser.LoginName;
>
>HTH
>
>
>--
>James Edelen
>Microsoft MVP - SharePoint Portal Server
>Microsoft MVP - Windows XP Media Center
>Microsoft Associate Expert
>Expert Zone -
http://www.microsoft.com/windowsxp/expertzone
>"Maria Teresa" <maria.petrullo@eniac.com> wrote in message
>news:020101c39cb8$79071a50$a301280a@phx.gbl...
>> Hello!!
>>
>> I have a Web part and I show some info in this web part.
>> The information that I want to show in the web part
change
>> depending what user is conected to sharepoint (V2.0). Is
>> there a way to detect in the web part what user is
logged
>> in sharepoint?
>>
>> Thanks in advance
>>
>> Maria Teresa
>
>
>.
>