How to retrieve all content database names for SharePoint 2016 web applications using SharePoint server object model?

How to retrieve all content database names for SharePoint 2016 web applications using SharePoint server object model?
InfoPath alternatives for form designing SharePoint

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:

How to retrieve all content database names for SharePoint 2016 web applications using SharePoint server object model?
How to retrieve all content database names for SharePoint 2016 web applications using SharePoint server object model?

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply