Is there a way to get a list of all of the community sites that a user has read/write access to, using an API that can be easily consumed by C#?

We would like to get a list of all of the community sites that a user has permission to both read and create posts in. Using the search API and searching for "WebTemplate:Community" brings up a list of all the communities, but it doesn't necessarily tell whether or not the user can access those communities.


You can very well use Search API for getting the list of community sites provided that you have a good crawl system maintained , probably continous crawl enabled. If you run the KeywordQuery search on current logged in user's context , it will give security trimmed results and so the user will have minimum read permission on the sites returned. Further more if you want to check if the user has contribute permission also , loop throught the result sites and check permissions.

KeywordQuery query = new KeywordQuery(site);
                    query.QueryText = string.Format("Path:{0} AND ContentClass:STS_Web AND WebTemplate:Community", site.Url);
                    query.RowLimit = 500;//max row limit is 500 for KeywordQuery
                    query.ResultsProvider = SearchProvider.Default;
                    query.EnableStemming = true;
                    query.TrimDuplicates = false;
                    query.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery;
                    query.KeywordInclusion = KeywordInclusion.AllKeywords;
                    SearchExecutor executor = new SearchExecutor();
                    ResultTableCollection resultTableCollection = executor.ExecuteQuery(query);
                    var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
                    var resultTable = resultTables.FirstOrDefault();
| improve this answer | |
  • Do you know how one would modify this for client side code? – user2528084 Mar 3 '14 at 20:57
  • @user2528084 for client side also the code is same. you will have to add client side dlls for search, and also the way you create Site object will be different. – Unnie Jun 6 '14 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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