I have developed a "web part" that has to be deployed on a Sharepoint server. I need the username of the user, who has logged in the sharepoint server within the web part.
How do I get that username?
I have developed a "web part" that has to be deployed on a Sharepoint server. I need the username of the user, who has logged in the sharepoint server within the web part.
How do I get that username?
Following worked for me:
and check this out.
//don't forget to add System.DirectoryServices.AccountManagement as reference and using System.DirectoryServices.AccountManagement;
You can use:
or
And you should check
this.Context.User.Identity.IsAuthenticated
as well to ensure there is a user logged in before trying to extract the username.You can also get current logged user ID by _spPageContextInfo property.
You will get current user's ID by _spPageContextInfo. Try this may help you.
SPContext.Current.Web.CurrentUser
Hey all, i got the answer for my question Hope this will work for you all... First add a reference to the MicrosoftSharepoint.dll file in your web part. then write using Microsoft.SharePoint;
Yours, Jigar <3