使用 C# 在 sharepoint 2007 中访问列表
我希望从 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();
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.
Is there any example code to access the sharepoint site using c#?
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法在 SharePoint 计算机上部署代码,那么您几乎必须使用 Web 服务。
列表网络服务就是您所追求的。
它位于 http://yousharepointsite.com/_vti_bin/Lists.asmx 上,并且默认情况下应处于打开状态。请注意,如果您的站点配置了FBA,则在查询lists.asmx之前,您必须使用_vti_bin/Authentication.asmx登录。
这是一篇文章,提供了您需要的所有信息:
http://sharepointmagazine.net/articles/writing-caml-queries-for-retriving-list-items-from-a-sharepoint-list
由于上述原因,请跳过使用对象模型来查询 SharePoint 列表并直接转至使用 SharePoint Web 服务通过 CAML 检索列表项。
这篇文章非常完整,所以我认为你应该对此感到满意。
根据您的编辑,我认为您无法像这样创建到远程站点的连接。您无法像那样使用 SQL 查询 SharePoint,您确实需要使用 CAML...
添加对 Web 服务的引用后:
阅读有关 GetListItems 此处
正如我所说,您需要使用 Web 服务。如果您尝试创建像这样的连接来直接查询数据库,那么您将走向死胡同。不推荐。
If you can't deploy code on the SharePoint machine, then you pretty much have to use the web services.
The lists web service is what you're after.
It will be located on http://yousharepointsite.com/_vti_bin/Lists.asmx and should be open by default. 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.
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
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.
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...
Once you've added the reference to the web service :
Read more on the GetListItems here
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.
不确定您尝试执行的操作是否可行,除非您使用适用于 SharePoint 的 ado.net 连接器,请查看 http: //www.bendsoft.com/net-sharepoint-connector/
它使您能够与 SharePoint 列表进行对话,就像它们在普通 sql 表中一样
在示例中插入一些数据
或选择列表数据到 DataTable
或使用填充 DataGrid 的辅助方法
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/
It enables you to talk to SharePoint lists as if they where ordinary sql-tables
In example to insert some data
Or to select list data to a DataTable
Or using a helper method to fill a DataGrid