如何使用凭据通过客户端对象模型连接到 SharePoint 列表? [英] How to use credentials to connect to a SharePoint list using the Client Side Object Model?

查看:18
本文介绍了如何使用凭据通过客户端对象模型连接到 SharePoint 列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to write an application to update a list on a SharePoint 2010 site.

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

I found the "SPSite" which I can create with the URL, but I can't figure out how to specify with which user I want to connect.

用户不是当前的windows用户,程序不在服务器上执行.

The user isn't the current windows user, and the program isn't executed on the server.

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

I saw the possibility to give a "SPUserToken", but in my method I only have the user, the domain, and his password, so how can I generate this user(and I think that this user is unknown on the system executing the code, but known on the server).

我可以在哪里指定?

推荐答案

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

Since you're using the client object model, you won't be working with the SPSite class (which is part of the server object model).

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

Instead, you should create an instance of the ClientContext class and supply your authentication credentials through its aptly-named Credentials property. Then you can use it to fetch the List object you want to update:

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.
}

这篇关于如何使用凭据通过客户端对象模型连接到 SharePoint 列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆