views:

58

answers:

2

Is it possible to retrieve the current user login used on sharepoint from an embedded Silverlight 4 application?

+1  A: 

On SharePoint 2010

Use client object model (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web.currentuser.aspx).

Something like:

public void DoStuff()
{
    ClientContext clientContext = ClientContext.Current;

    clientContext.Load(clientContext.Web, s => s.CurrentUser);
    clientContext.ExecuteQueryAsync((sender, args) => {
        var currentUser = clientContext.Web.CurrentUser;
    }, null);
}

On SharePoint 2007

Unfortunatly, the client object model does not exist on SP2007. What I did before is this:

I guess there is a WebService you can use directly to Silverlight, but I don't know one on the top of my head.

Nico
Thank you Nico, forgot to mention that it is on Microsoft Online (BPOS) and then in Sharepoint 2007...
Eric
I've updated the post to include SP2007. Both solutions will work on BPOS (no server code).
Nico
A: 

You can use Object models as long as you stay on the Silverlight application within your box. If you want to work in a site located in someone else's system. Then Object Model wont work. Try using Sharepoint's native webservices.

Take a look at Authentication.asmx's Login Method for Forms Authenticated site. You should find it here http://server/site/_vti_bin/Authentication.asmx (look at this sample site http://www.wssdemo.com/Pages/_vti_bin/Authentication.asmx )

For windows authenticated site, you will need to look at NetworkCredentials for getting the current user credentials.

Aswin Ramakrishnan
mmhh yes but NetworkCredentials is not accessible in Silverlight...I found a way passing the sharepoint ID as parameter to the silverlight application but then it won't work as 'Desktop' silverlight application...And using Microsoft Online, the identification is not Form based...Thank you for you help!
Eric
@Eric.. Yes, NetworkCredentials is not accessible through Silverlight. You can use a Web Service referencing your local Endpoint and you can change the endpoint and the Credentials in your WebService. Or you can set the values for Authentication proxy's ClientCredentials on the Client side itself. It will work. Sorry for not mentioning this.
Aswin Ramakrishnan
@Eric.. If it is not a Forms Authenticated Site. Use UserGroup.asmx to get User Data. You should find it here. http://Root/Site/_vti_bin/UserGroup.asmx, where Root is your server name and site is your site's name. Hope this helps
Aswin Ramakrishnan