使用 c# 的 sharepoint 2007 中的访问列表 [英] access list in sharepoint 2007 using c#
问题描述
我希望从 sharepoint 2007 中的几个不同的客户列表中编译数据
I'm looking to compile data from a few diffrent custome lists in sharepoint 2007
它是一个托管的共享点站点,所以我无权访问机器后端.
Its a hosted sharepoint site so I don't have access to the machine backend.
有没有使用c#访问sharepoint站点的示例代码?
Is there any example code to access the sharepoint site using c#?
这是我目前的代码(我收到错误无法连接到 Sharepoint 站点''.稍后再试.)
here is my code thus far (i get the error Cannot connect to the Sharepoint site ''. Try again later.)
DataSet dt = new DataSet();
string query = "SELECT * FROM list";
string site = "http://sp.markonsolutions.com/Lists/Security/";
string list = "35E70EO4-6072-4T55-B741-4B75D5F3E397"; //security db
string myConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes; DATABASE="+site+";LIST={"+list+"};";
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = myConnectionString;
OleDbCommand myAccessCommand = new OleDbCommand(query,myConnection);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);
myConnection.Open();
myDataAdapter.Fill(dt);
//execute queries, etc
myConnection.Close();
推荐答案
除非您使用适用于 SharePoint 的 ado.net 连接器,否则不确定您尝试执行的操作是否可行,请查看 http://www.bendsoft.com/net-sharepoint-connector/
Not sure if what you try to do is possible unless you use an ado.net connector for SharePoint, have a look at http://www.bendsoft.com/net-sharepoint-connector/
它使您可以像处理普通 sql 表一样与 SharePoint 列表进行对话
It enables you to talk to SharePoint lists as if they where ordinary sql-tables
以插入一些数据的例子
public void SharePointConnectionExample1()
{
using (SharePointConnection connection = new SharePointConnection(@"
Server=mysharepointserver.com;
Database=mysite/subsite
User=spuser;
Password=******;
Authentication=Ntlm;
TimeOut=10;
StrictMode=True;
RecursiveMode=RecursiveAll;
DefaultLimit=1000;
CacheTimeout=5"))
{
connection.Open();
using (SharePointCommand command = new SharePointCommand("UPDATE `mytable` SET `mycolumn` = 'hello world'", connection))
{
command.ExecuteNonQuery();
}
}
}
或者选择列表数据到DataTable
Or to select list data to a DataTable
string query = "SELECT * FROM list";
conn = new SharePointConnection(connectionString);
SharePointDataAdapter adapter = new SharePointDataAdapter(query, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
或者使用辅助方法填充 DataGrid
Or using a helper method to fill a DataGrid
string query = "Select * from mylist.viewname";
DataGrid dataGrid = new DataGrid();
dataGrid.DataSource = Camelot.SharePointConnector.Data.Helper.ExecuteDataTable(query, connectionString);
dataGrid.DataBind();
Controls.Add(dataGrid);
这篇关于使用 c# 的 sharepoint 2007 中的访问列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!