1

I am currently developping a C# application which has to retrieve some data from a SharePoint website through a CAML request.

I successfully get everything I need except one information : the login of the user who checked out a file.

For example, if the user who checked out a file use a login looking like "john.doe", the CheckoutUser retrieved by the request is "Doe, John".

Since I need to compare the credentials of the local user with the ones of the user who checked the file, this is annoying.

Does anyone have an idea on how I could achieve that?

Thanks.

EDIT

This code seems to work well in my situation:

public User GetCurrentUser()
{ 
    using (ClientContext clientContext = _GetClientContext())
    {
        var web = clientContext.Web;
        clientContext.Load(web);
        clientContext.Load(web.CurrentUser);
        clientContext.ExecuteQuery();
        return clientContext.Web.CurrentUser;
    }
}

Then, we compare this user's ID with the CheckedOutUserID accessible through CAML request. So finally, we didn't figure out how to retrieve the needed login through SharePoint web service request, but this work around seems to do the job well.

2
  • "Doe, John" might be the "Name" property of the user, you can get the same value in c# using SPUser class's "Name" property. Commented Sep 25, 2013 at 14:09
  • the problem is that I request the webservice of the SharePoint site to retrieve the data I need, since I cannot have a development environment with SharePoint and Visual Studio on the same computer. As a result, I cannot use classes like SPUser, which are in Microsoft.SharePoint.dll, and can only request the API using CAML and parse the result "manually". Isn't there a way to do the trick with my configuration? Commented Sep 25, 2013 at 15:33

2 Answers 2

0

If you CAML query has returned the item collection you can do

foreach(SPListItem item in collection)
{
    SPFieldUserValue userValue = new SPFieldUserValue(web, item["CheckoutUser"].ToString());
    SPUser checkoutUser= userValue.User;
   //Here you can compare with SPWeb.CurrentUser.ID and checkoutUser.ID
}
5
  • the problem is that I request the webservice of the SharePoint site to retrieve the data I need, since I cannot have a development environment with SharePoint and Visual Studio on the same computer. As a result, I cannot use classes like SPUser, which are in Microsoft.SharePoint.dll, and can only request the API using CAML and parse the result "manually". Isn't there a way to do the trick with my configuration? Commented Sep 25, 2013 at 15:32
  • One question. How do yo want compare the credentials? By the NT login name? Commented Sep 25, 2013 at 15:38
  • By comparing it either with the user account executing the application, or to the credentials that he entered in a configuration file accessible by the application. Commented Sep 25, 2013 at 15:42
  • Can you post your C# code that calls the webservice so that I can help you better? Commented Sep 25, 2013 at 15:44
  • We found a workaround for our problem, see the edit. Thanks for your answers :) Commented Sep 26, 2013 at 8:47
0

See the edit for the workaround we finally used in our context. It doesn't do the exact same thing, but still do the trick.

1
  • Thanks for coming back with your findings, but it's clearer if you put the answer in the answer rather than editing the question :)
    – lgaud
    Commented Oct 1, 2013 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.