How to get all site collections in a web application

I want to list all site collections in my web application; the goal is to list all mysites created by users.

Like:

/members/sites/sqladmin
/members/sites/sqluser
/members/sites/sqluser1
/members/sites/sqluser2
/members/sites/user1
+3
source share
4 answers

To access all site collections within this web application, there is, of course, the SPWebApplication.Sites property . To access a specific web application, you can use this code:

SPWebApplication webApp = SPWebApplication.Lookup(new Uri("http://my-web-app-url:80/"));

(see MSDN here ).

+7
source

Use a property for this SPWebApplication.Sites.

+2
source

On the Central Administration home page, click Application Management.

On the Application Management page, in the Site Collections section, click View All Site Collections.

The site collection list page lists all site collections in the web application.

0
source

Use the code below to programmatically retrieve all site application site collections. url parametter = URL of the web application.

        public DataTable GetAllSiteCollections(string url)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("URL");
            dt.Columns.Add("Name");
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPWebApplication webApplication = SPWebApplication.Lookup(new Uri(url));
                foreach (SPSite site in webApplication.Sites)
                {
                    dt.Rows.Add(new object[] { site.Url, site.Url });

                }

            });

            return dt;
        }
0
source

Source: https://habr.com/ru/post/1782754/


All Articles