Home > SharePoint Development > How to get all subsites for specific user in sharepoint using c#

How to get all subsites for specific user in sharepoint using c#

 string user="Domain\UserName";
 string topSite="http://server:port";
 
 public ArrayList FindExistingUserSites(string user, string topSite)
        {
            ArrayList arAssignSites = new ArrayList();
            SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(topSite))
    {
        try
        {
            for (int i = 0; i < site.AllWebs.Count; i++)
            {
                SPWeb web = site.AllWebs[i];
                SPUser oUser = web.AllUsers[user];
                foreach (SPRole rl in oUser.Roles)
                {
                    arAssignSites.Add(web.Name + " – " + rl.Name);
                }

                web.Dispose();
            }
        }
        catch (Exception ex)
        {

        }
    }
});
            return arAssignSites;

        }

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: