Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

SharePoint 2010 - SPContentDataBaseCollection Class

Viewed:  1781 
Posted On:  14/03/2013 10:07:01 
In this article I am going to show how we can use SPContentDataBaseCollection Class. 

The SPContentDatabase class represents a content database in the Microsoft Windows SharePoint Services deployment. In this article I am going to show how we can use this SPContentDatabaseCollection. 

Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)

Now we will learn about this class by making a program. 
Open Visual Studio -> Create New Project -> 
Now Add reference of Microsoft.SharePoint.dll from the 14 hive location:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI

Now change Target frame work to .Net 3.5 by Right Clicking on your solution explorer -> Click Property.


Image 1.

Now Set Platform target to x64...


Image 2.

Now your program output will be...


Image 3.

Code for this program is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration; 

namespace SharePoint2010_SPContentDataBase
    public partial class Form1 : Form
        public Form1()
        private void button1_Click(object sender, EventArgs e)
            SPWebApplication spWeb = SPWebApplication.Lookup(new Uri("http://localhost:3000"));
            SPContentDatabaseCollection spconDbCol = spWeb.ContentDatabases;

foreach (SPContentDatabase spConDb in spconDbCol)
                textBox1.Text = spConDb.Name + Environment.NewLine + spConDb.DatabaseConnectionString;

         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us