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);
MySQLConnection.Open();
MySQLCommand.ExecuteNonQuery();
// 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.Items.Add(Docds.Tables["Docs"].Rows[i].ItemArray[2].ToString());
//lstdocuments.DisplayMember = Docds.Tables["Docs"].Rows[i].ItemArray[2].ToString();
//lstdocuments.ValueMember = Docds.Tables["Docs"].Rows[i].ItemArray[1].ToString();
}
}
}
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);
MySQLConnection.Open();
MySQLCommand.ExecuteNonQuery();
// 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.Items.Add(Docds.Tables["Docs"].Rows[i].ItemArray[2].ToString());
//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.
1 comment:
Direct access to the database as you suggest is not supported by Microsoft.
Post a Comment