Read SharePoint documents using SQL Server query

Retrieve documents form the SharePoint website and display the same in your Windows forms application. No need to use SharePoint webservices or SharePoint Object model. Just run through the query to fetch the documents from the SharePoint using SQL query.
Sample Code:
private void btnload_Click(object sender, EventArgs e)
string RootSite = txtsharepointsite.Text.ToString(); // "http://w2czbmlg01:12345/";
// Opening SQL connection for Microsoft SQL Server 2005
SqlConnection MySQLConnection = new SqlConnection(@"Data Source=W2CZBMLG01;Initial Catalog=WSS_Content_12345;Integrated Security=True");
// Passing SQL command text
string strSQLcmd = "SELECT CONVERT(nvarchar(36), Id) AS ID, '" + RootSite + "'+ DirName + '/' + LeafName AS Name, LeafName FROM dbo.Docs WHERE (LeafName NOT LIKE 'template%') AND LeafName LIKE '%.doc' ORDER BY DirName, LeafName";
SqlCommand MySQLCommand = new SqlCommand (strSQLcmd, MySQLConnection);
// Dats set
DataSet Docds = new DataSet("Docs");
SqlDataAdapter MySQLAdapter = new SqlDataAdapter();
MySQLAdapter.SelectCommand = MySQLCommand;
MySQLAdapter.Fill(Docds, "Docs");
for (int i = 0; i < Docds.Tables["Docs"].Rows.Count; i++)
// list populates
//lstdocuments.DisplayMember = Docds.Tables["Docs"].Rows[i].ItemArray[2].ToString();
//lstdocuments.ValueMember = Docds.Tables["Docs"].Rows[i].ItemArray[1].ToString();

Just create a Windows Form application and add this code in the form load or button click to get the result.


Gil Salcedo said…
Direct access to the database as you suggest is not supported by Microsoft.

Popular posts from this blog

ASP.NET website "Cannot read configuration file due to insufficient permissions" in IIS 7 and Windows Server 2008

Error occurred in deployment step 'Install app for SharePoint': The System Account cannot perform this action.

Windows Server AppFabric: installation error , While installing SharePoint prerequisite installer