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

查看:97
本文介绍了如何使用凭据通过客户端对象模型连接到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).

在哪里可以指定该用户?

Where can I specify that?

推荐答案

由于您正在使用客户端对象模型,因此您将无法使用SPSite 类(它是 server 对象模型的一部分)。

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 类,并通过适当命名的凭据属性。然后,您可以使用它来获取要更新的列表对象:

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天全站免登陆