如何使用凭据通过客户端对象模型连接到SharePoint列表?

编程入门 行业动态 更新时间:2024-10-25 16:30:48
本文介绍了如何使用凭据通过客户端对象模型连接到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("yourserver/")) { context.Credentials = new NetworkCredential("user", "password", "domain"); List list = context.Web.Lists.GetByTitle("Some List"); context.ExecuteQuery(); // Now update the list. }

更多推荐

如何使用凭据通过客户端对象模型连接到SharePoint列表?

本文发布于:2023-11-16 04:29:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:凭据   连接到   如何使用   客户端   模型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!