locked
How to get the sharepoint current logged in user name in silverlight application using object model RRS feed

  • Question

  • Hi friends,

    Can anyone help me how to get the sharepoint current logged in user name in silverlight application using object model?

    thanks in advance.

    Rajan Garg

    Tuesday, July 13, 2010 5:17 AM

Answers

  • Hi Rajan,

    Assuming your silverlight application to be hosted in your Sharepoint site you can pass the parameters to the SL app from the page where you have placed your XAP.

    HTH. Mark as answered if that helps :-)

    Regards,

    Vidds

     

    Tuesday, July 13, 2010 6:51 AM

All replies

  • Hi Rajan,

    Not sure of getting it through sharepoint object model but you can use  

    HttpContext.Current.User.Identity.Name to and then query the Activedirectory using this name to get  the details and pass on to Silverlight.

    HTH. Mark as answered if that helps :-)

    Regards,

    Vidds

     

    Tuesday, July 13, 2010 6:29 AM
  • Thanks Vidds...

    i have my application in silverlight. this way do i need to create one more application which will set the current user parameter? Please correct me if i am wrong.

    Tuesday, July 13, 2010 6:39 AM
  • Hi Rajan,

    Assuming your silverlight application to be hosted in your Sharepoint site you can pass the parameters to the SL app from the page where you have placed your XAP.

    HTH. Mark as answered if that helps :-)

    Regards,

    Vidds

     

    Tuesday, July 13, 2010 6:51 AM
  • I finally found an answer for this question:

     

        Private oCurrentUser As User

     

        Private Sub GetCurrentUser()

            Dim oContext As Microsoft.SharePoint.Client.ClientContext

            Try

                oContext = New Microsoft.SharePoint.Client.ClientContext(sServerUrl)

                oCurrentUser = oContext.Web.CurrentUser

                oContext.Load(oCurrentUser)

                oContext.ExecuteQueryAsync(AddressOf GetCurrentUsersSucceeded, Nothing)

            Catch ex As Exception

                MessageBox.Show(ex.Message)

            End Try

        End Sub

        Private Sub GetCurrentUsersSucceeded(ByVal sender As Object, ByVal args As Microsoft.SharePoint.Client.ClientRequestSucceededEventArgs)

            Dispatcher.BeginInvoke(AddressOf GetCurrentUserData)

        End Sub

        Private Sub GetCurrentUserData()

            Dim sMsg As String = ""

            Try

                sMsg &= oCurrentUser.Title & " - " & oCurrentUser.Email & " - " & oCurrentUser.LoginName & vbCrLf

                MessageBox.Show(sMsg)

            Catch ex As Exception

                MessageBox.Show(ex.Message)

            End Try

        End Sub

     

     

    Wednesday, August 11, 2010 8:06 AM
  • You can get it easily using

    HttpContext.Current.User.Identity.Name
    Also make sure your web application in IIS has ASP.NET Impersonation and Windows Authentican turned on.
    and all other options turned off. 
     
    maulik.soni
    codesnipets.wordpress.com
    Monday, August 23, 2010 3:49 PM
  • hi,

    can you give some short example...

    best regards...

    mehmet r. inceoglu

    Friday, November 5, 2010 8:49 AM
  • hi vidds,

    can you give a short code example how to do this...

    best regards.

    mehmet r. inceoglu

    Friday, November 5, 2010 8:50 AM
  • use _LogonUser_ SharePoint automatically replace with current user information...

    Saturday, December 11, 2010 11:28 AM
  • private string CurrentUserName()
            {

                string userName = "NA";
                SPContext currentContext;
                try
                {
                    //Getting the current context           
                    currentContext = SPContext.Current;
                }
                catch (InvalidOperationException)
                {
                    currentContext = null;
                }
                if (currentContext != null && currentContext.Web.CurrentUser != null)
                {
                    userName = SPContext.Current.Web.CurrentUser.Name;
                }


                return userName;
            }

    Monday, January 31, 2011 11:24 AM