【问题标题】:How to use credentials to connect to a SharePoint list using the Client Side Object Model?如何使用凭据通过客户端对象模型连接到 SharePoint 列表?
【发布时间】:2011-09-16 23:26:21
【问题描述】:

我需要编写一个应用程序来更新 SharePoint 2010 网站上的列表。

我找到了可以使用 URL 创建的“SPSite”,但我不知道如何指定要连接的用户。

用户不是当前的windows用户,并且程序没有在服务器上执行。

我看到了提供“SPUserToken”的可能性,但在我的方法中我只有用户、域和他的密码,所以我怎样才能生成这个用户(我认为这个用户在系统上是未知的执行代码,但在服务器上已知)。

我在哪里可以指定?

【问题讨论】:

    标签: c# .net sharepoint sharepoint-2010 sharepoint-clientobject


    【解决方案1】:

    由于您使用的是客户端对象模型,因此您不会使用 SPSite 类(它是 服务器 对象模型的一部分)。

    相反,您应该创建ClientContext 类的实例,并通过其恰当命名的Credentials 属性提供您的身份验证凭据。然后您可以使用它来获取您要更新的List 对象:

    using System.Net;
    using Microsoft.SharePoint.Client;
    
    using (ClientContext context = new ClientContext("http://yourserver/")) {
        context.Credentials = new NetworkCredential("user", "password", "domain");
        List list = context.Web.Lists.GetByTitle("Some List");
        context.ExecuteQuery();
    
        // Now update the list.
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多