0
votes

Is there a way to get the results of UserGroup.GetUserInfo but without having to specify the user I'm querying for, such as with UserGroup.GetRolesAndPermissionsForCurrentUser?

In particular, I'm trying to get the User ID (so that I can tell if a Document is checked out to the currently logged in user, or not). Unfortunately, I am using a SmartCard to provide credentials -- there is no username or password entered for the actual document library -- So I can't use domain\username for GetUserInfo, which is how I do it for non-smart card usage.

Additionally, I'm on iOS, so I don't really have any nice SharePoint APIs to use -- everything needs to be available through the 2007/2010 SOAP WebService APIs

Thanks!

1

1 Answers

1
votes

You should be able to use UserGroup.GetCurrentUserInfo. The Sharepoint SOAP documentation can be found here http://msdn.microsoft.com/en-us/library/websvcusergroup.usergroup.getcurrentuserinfo(v=office.14).aspx.

If you have access to a Sharepoint instance you can check the SOAP envelope and response here: htttp://your.sharepointserver.com/_vti_bin/usergroup.asmx?op=GetCurrentUserInfo (do not use this URL in the actual request from your app).

Below is an example implementation based on AFNetworking and a sub classed AFHTTPClient.

// Get user info for currently signed in user
- (void)currentUserInfoWithSuccessBlock:(void(^)(SharepointCurrentUserResponse *response))successBlock
                              failBlock:(void(^)(NSError *error))failBlock {

  NSMutableURLRequest *request = [self requestWithMethod:@"POST"
                                                    path:@"_vti_bin/UserGroup.asmx"
                                              parameters:nil];

  NSString *soapEnvelope =
    @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    @"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
    @"<soap:Body>"
    @"<GetCurrentUserInfo xmlns=\"http://schemas.microsoft.com/sharepoint/soap/directory/\" />"
    @"</soap:Body>"
    @"</soap:Envelope>";

  // Set headers
  [request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  [request setValue:@"http://schemas.microsoft.com/sharepoint/soap/directory/GetCurrentUserInfo" forHTTPHeaderField:@"SOAPAction"];

  // Content length
  NSString *contentLength = [NSString stringWithFormat:@"%d", soapEnvelope.length];
  [request setValue:contentLength forHTTPHeaderField:@"Content-Length"];

  // Set body
  [request setHTTPBody:[soapEnvelope dataUsingEncoding:NSUTF8StringEncoding]];

  AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request
    success:^(AFHTTPRequestOperation *operation, id responseData) {
      NSString *xmlString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
      NSLog(@"XML response : %@", xmlString);

      // Parse the response
      SharepointCurrentUserResponse *response = ...

      successBlock(reponse);
    }
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Get user info failed with reason: %@ status code %d",
            error, operation.response.statusCode);

      failBlock(error);
  }];

  // Que operation
  [self enqueueHTTPRequestOperation:operation];
}