แชร์ผ่าน


SharePoint and GetUserCollectionFromSite

So, I'm messing around with the Windows SharePoint Services Web services it exposes. They are legion, and they are very, very cool. One of the Web methods I needed to call for an app I am writing gets the users that have been given perms for a Document Workspace.

Here are just a few of the lines of code I use to get the job done:

spUsersSurvey.UserGroup spSvc=new spUsersSurvey.UserGroup();

spSvc.Credentials = System.Net.CredentialCache.DefaultCredentials;

XmlNode users=spSvc.GetUserCollectionFromSite();

What baffled me is what the list contains. I was looking for a list of those who have been assigned permissions in the Document Workspace expecting it to return the three or four people I have added to the workspace. Instead, I got back a list of 30+ people. The game was on.

The reference documentation actually does give a clue, but it is not as clear as it could be. Basically, there are two calls you can make:

  • GetUserCollectionFromSite
  • GetUserCollectionFromWeb

The key is to use the correct method. Calling GetUserCollectionFromWeb actually gave me what I wanted. For example, if this is the full address of the document workspace: https://myserver/mysite/myworkspaceA, and I have added three people there with permissions, then GetUserCollectionFromWeb returns that list of users. However, if I pass the same URL to GetUserCollectionFromSite, the list will be much longer and this is by design. This is because GetUserCollectionFromSite returns the list of users for the site, not the workspace. In my example, the latter method would return the list of users for mysite. If other workspaces have been defined on this site, such as myworkspaceB, myworkspaceC, etc., then the GetUserCollectionFromSite method will return users that have been added to those workspaces (along with myworkspaceA), because they have been permission to the site.

The documentation is correct, and, in retrospect, it is fairly straight forward.The key is to know that "Web" means workspace in the method call.

 Rock thought for the day: Spent my commute yesterday listening to the 15 minute guitar solo that is "Why am I so tired" on the Smashing Pumpkins Earphoria CD. Just fantastic. Billy Corgan is simply one of the best guitarist in rock and roll. His work as lyricist and composer is usually recognized, but his guitar work is not singled out as it should be.

Rock on

Comments