【问题标题】:access list in sharepoint 2007 using c#使用c#在sharepoint 2007中的访问列表
【发布时间】:2011-07-31 19:23:17
【问题描述】:

我希望从 sharepoint 2007 中的几个不同客户列表中编译数据

它是一个托管的共享点站点,所以我无权访问机器后端。

是否有任何示例代码可以使用 c# 访问共享点站点?

这是我目前的代码(我收到错误无法连接到 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();

【问题讨论】:

    标签: c# sharepoint sharepoint-2007 sharepoint-list


    【解决方案1】:

    如果您无法在 SharePoint 机器上部署代码,那么您几乎必须使用 Web 服务。

    列表网络服务就是您所追求的。

    它将位于http://yousharepointsite.com/_vti_bin/Lists.asmx,默认情况下应该是打开的。请注意,如果您的站点配置了 FBA,则必须在查询 lists.asmx 之前使用 _vti_bin/Authentication.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(...);
    

    阅读更多关于 GetListItems here

    就像我说的,您需要使用网络服务。如果您尝试创建这样的连接以直接查询数据库,那么您将走向死胡同。不推荐。

    【讨论】:

    • 我不知道 FBA 或 _vit_bin/authentication.asmx 是什么
    • 那么你可能没有使用它们。 FBA 是基于表单的身份验证。您可能在您的共享点站点上使用 Windows 身份验证,因此只需使用 lists.asmx 和我提供的链接即可。
    【解决方案2】:

    除非您使用适用于 SharePoint 的 ado.net 连接器,否则不确定您尝试执行的操作是否可行,请查看 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);
    

    【讨论】:

    • 我相信你必须在同一台机器上。他说他无权访问运行 SharePoint 的机器。
    • 那么上面的解决方案非常好,所描述的 Ado.net 连接器使用 SharePoint API,因此它可以在 SharePoint 内部(用于 webparts)和外部进行集成时使用!
    • 哇,我不知道它可以远程使用!我一定会再次检查并试一试。在我的书中,任何让你不使用 CAML 的东西都很棒!
    • 非常有趣的想法,我要去看看 - 我确实担心泄漏抽象定律会以惊人的方式出现。
    • 对不起,我已经离开了,因为时间的缘故,我认为这是正确的,我会在本周晚些时候尝试并报告
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    相关资源
    最近更新 更多