Here we will discuss how we can retrieve all content database name for web applications using SharePoint 2016 server object model. In my last post, we have discussed how to retrieve all web application names from SharePoint farm using server object model in SharePoint 2016.
Here I have shown in a windows application. I have SharePoint 2016 installed on the same machine, so I can add Microsoft.SharePoint.dll into the windows application and can write server-side code inside it.
You can see the SharePoint 2016 installation steps and SharePoint 2016 new and improved features.
Below is the full code to get the content database name:
string s = string.Empty;
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>(“”);
foreach (SPWebApplication webapp in service.WebApplications)
foreach (SPSite site in webapp.Sites)
s += “Site Collection URL: ” + site.Url + ” Content Database Name: ” + site.ContentDatabase.Name + “\n”;
label9.Text = s;
Once you run the code, it will display all site collection urls and corresponding content database names like below:
Hope this will be helpful.
-: FREE PDF e-Book Download :-
51 JSOM Examples in SharePoint Online
You May Also like the Following SharePoint Online Tutorials: