[英]access list in sharepoint 2007 using c#
I'm looking to compile data from a few diffrent custome lists in sharepoint 2007 我想从sharepoint 2007中的几个不同的客户列表中编译数据
Its a hosted sharepoint site so I don't have access to the machine backend. 它是一个托管的sharepoint站点,所以我无法访问机器后端。
Is there any example code to access the sharepoint site using c#? 是否有使用c#访问sharepoint站点的示例代码?
here is my code thus far (i get the error Cannot connect to the Sharepoint site ''. Try again later. ) 这是我到目前为止的代码(我收到错误无法连接到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();
If you can't deploy code on the SharePoint machine, then you pretty much have to use the web services. 如果您无法在SharePoint计算机上部署代码,那么您几乎必须使用Web服务。
The lists web service is what you're after. 列表Web服务就是您所追求的。
It will be located on http://yousharepointsite.com/_vti_bin/Lists.asmx and should be open by default. 它将位于http://yousharepointsite.com/_vti_bin/Lists.asmx上 ,默认情况下应该打开。 Note that if your site is configured with FBA, you will have to use the _vti_bin/Authentication.asmx to log in before you query lists.asmx.
请注意,如果您的站点配置了FBA,则在查询lists.asmx之前,必须使用_vti_bin / Authentication.asmx登录。
Here is an article that gives all the information you need : 这篇文章提供了您需要的所有信息:
http://sharepointmagazine.net/articles/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list http://sharepointmagazine.net/articles/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list
For the reasons mentioned above, skip the part on using the object model to query SharePoint lists and go directly to Retrieving list items with CAML using the SharePoint web services. 由于上述原因,请跳过使用对象模型查询SharePoint列表的部分,然后直接转到使用SharePoint Web服务检索CAML列表项。
The article is pretty complete, so I think you should be OK with that. 这篇文章非常完整,所以我觉得你应该对此好。
As per your edit, I don't think that you can create a connection to your remote site like that. 根据您的编辑,我认为您不能像这样创建与远程站点的连接。 You can't query SharePoint with SQL like that, you really need to use CAML...
您无法像这样使用SQL查询SharePoint,您确实需要使用CAML ...
Once you've added the reference to the web service : 一旦您添加了对Web服务的引用:
ListService listsClient = new ListService.Lists();
listsClient.Url = @"http://sp.markonsolutions.com/" + @"/_vti_bin/lists.asmx";
listsClient.Credentials = System.Net.CredentialCache.DefaultCredentials;
listsClient.GetListItems(...);
Read more on the GetListItems here 在这里阅读有关GetListItems的更多信息
Like I said, you need to use the web services. 就像我说的,你需要使用网络服务。 You are heading towards a dead end if you are trying to create connection like that to query the database directly.
如果您尝试创建类似的连接以直接查询数据库,那么您将走向死胡同。 It is not recommended.
不推荐。
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/ 除非您使用适用于SharePoint的ado.net连接器,否则不确定您尝试执行的操作是否可行,请查看http://www.bendsoft.com/net-sharepoint-connector/
It enables you to talk to SharePoint lists as if they where ordinary sql-tables 它使您可以与SharePoint列表进行通信,就像它们在普通的sql表中一样
In example to insert some data 在示例中插入一些数据
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();
}
}
}
Or to select list data to a DataTable 或者选择列表数据到DataTable
string query = "SELECT * FROM list";
conn = new SharePointConnection(connectionString);
SharePointDataAdapter adapter = new SharePointDataAdapter(query, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
Or using a helper method to fill a DataGrid 或者使用辅助方法填充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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.