[英]Access Sharepoint 2007 (MOSS) Environment from Sharepoint 2010 Environment using C# Console Application
[英]access list in sharepoint 2007 using c#
我想从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,则在查询lists.asmx之前,必须使用_vti_bin / Authentication.asmx登录。
这篇文章提供了您需要的所有信息:
由于上述原因,请跳过使用对象模型查询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(...);
就像我说的,你需要使用网络服务。 如果您尝试创建类似的连接以直接查询数据库,那么您将走向死胡同。 不推荐。
除非您使用适用于SharePoint的ado.net连接器,否则不确定您尝试执行的操作是否可行,请查看http://www.bendsoft.com/net-sharepoint-connector/
它使您可以与SharePoint列表进行通信,就像它们在普通的sql表中一样
在示例中插入一些数据
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.