How to retrieve the list of sharepoint sites, user has access to , from a windows application

Tag: sharepoint Author: a1928 Date: 2009-07-14

I have to retrieve a list of all the share point sites to which i have access from a windows application (C#) .I am planning to use Share point web sericves but I am new to share point. Any pointer which share point web service(s) could provide me the required information.

Other Answer1

If you want to use the API instead then I would suggest you do the following to return all the sub webs for the current user without having to use elevated priviliges.

using(SPSite site = new SPSite("http://example/site/"))
{
    using (SPWeb web = site.OpenWeb())
    {
    	SPWebCollection webCollection = web.GetSubwebsForCurrentUser();
    }
}

comments:

Thanks for this.

Other Answer2

Webs.asmx should do the trick. Here's a snippet to get you started.

Dim rootNode As XmlNode = Nothing

Using ws As New WebsProxy.Webs
    ws.PreAuthenticate = True
    ws.UseDefaultCredentials = True
    ws.Url = <site collection address> + "/_vti_bin/webs.asmx"
    rootNode = ws.GetWebCollection()
End Using

Other Answer3

I know this question is really old, but since it's still one of the first/only results I thought I would share the solution I found that uses SharePoint search to solve the problem. Not only is it really fast, you can tweak the query to your liking or even create a custom search scope to limit the results.

string queryText = "SELECT url, title " +
                    "FROM Scope() " +
                    "WHERE \"Scope\" = 'All Sites' " +
                    "AND (ContentClass = 'STS_Site' OR ContentClass = 'STS_Web')";

SearchServiceApplicationProxy proxy = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(SPContext.Current.Site));
FullTextSqlQuery searchQuery = new FullTextSqlQuery(proxy);
searchQuery.ResultsProvider = SearchProvider.Default;
searchQuery.ResultTypes = ResultType.RelevantResults;
searchQuery.EnableStemming = false;
searchQuery.TrimDuplicates = true;
searchQuery.QueryText = queryText;
searchQuery.RowLimit = 1000; 
ResultTableCollection results = searchQuery.Execute();
ResultTable result = results[ResultType.RelevantResults];

while (result.Read())
{
    string url = result.GetString(0);
    string title = result.GetString(1);

    ...
}

The query above can also be passed to /vti_bin/search.asmx, but that's a little more complicated. More info can be found here: http://msdn.microsoft.com/en-us/library/ee872313.aspx

Other Answer4

There's no way to do this with the out of the box web services I think. You could however write your web service, deploy that to your sharepoint farm and then call that service.

In it should be a method that takes a username and then using SPSecurity.RunWithElevatedPriviliges loops through the site collections / sites to determine if the user provided has access to each.

Other Answer5

Looking for a similar solution, I came across SharePoint SUSHI on CodePlex. I haven't tried it yet, but it looks like it'll do what you're looking for. Or if you really want to write your own, you could check out the code and see how they're doing it.