使用c#在sharepoint 2007中访问列表
本文关键字:访问 列表 2007 sharepoint 使用 | 更新日期: 2023-09-27 17:49:00
我正在寻找从sharepoint 2007中几个不同的客户列表编译数据
这是一个托管的sharepoint网站,所以我不能访问机器后端。
是否有使用c#访问sharepoint站点的示例代码?这是我的代码到目前为止(我得到错误不能连接到Sharepoint网站"。)
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机器上部署代码,那么你几乎必须使用web服务。
列表web服务是你所需要的。
它将位于http://yousharepointsite.com/_vti_bin/Lists.asmx,默认情况下应该是打开的。注意,如果您的站点配置了FBA,则必须使用_vti_bin/Authentication。查询list . Asmx .
这篇文章提供了你需要的所有信息:
http://sharepointmagazine.net/articles/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list由于上面提到的原因,请跳过使用对象模型查询SharePoint列表的部分,直接使用SharePoint web服务使用CAML检索列表项。
这篇文章很完整,所以我想你应该可以接受。
根据你的编辑,我不认为你可以创建一个连接到你的远程站点。你不能用这样的SQL来查询SharePoint,你真的需要使用CAML…
一旦你添加了对web服务的引用:
ListService listsClient = new ListService.Lists();
listsClient.Url = @"http://sp.markonsolutions.com/" + @"/_vti_bin/lists.asmx";
listsClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
listsClient.GetListItems(...);
在这里阅读更多关于getlisttitems的信息
就像我说的,你需要使用web服务。如果您试图创建这样的连接来直接查询数据库,那么您将走向死胡同。不确定你想做的是否可能,除非你使用ado.net连接器SharePoint,看看http://www.bendsoft.com/net-sharepoint-connector/
它使您能够像普通的sql表一样与SharePoint列表对话
插入数据
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
string query = "SELECT * FROM list";
conn = new SharePointConnection(connectionString);
SharePointDataAdapter adapter = new SharePointDataAdapter(query, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
或者使用辅助方法填充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);