使用凭据与SharePoint的客户端对象模型互动? [英] Use credentials to interact with the Client Object Model of Sharepoint?

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

问题描述

我需要写有更新在SharePoint 2010年某个列表的小软件。



我找到了的SPSite我可以与URL创建,但我无法弄清楚如何指定与我想要连接的用户。



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



只见方法可行送SPUserToken,但在我的方法我只有用户,域和他的密码,所以我怎么能生成该用户(我认为这个用户是执行代码的系统上未知的,但在服务器上已知的)



我在哪里可以指定?



感谢您!


解决方案

由于您使用的客户端对象模型,你不会与的SPSite 的类中工作(这是部分服务器的对象模型)。



相反,你应该创建的 ClientContext 类,并通过恰当地命名的凭据财产。然后,你可以用它来获取列表要更新对象





<预类=郎-CS prettyprint-覆盖> 使用System.Net;
使用Microsoft.SharePoint.Client;

使用(ClientContext上下文=新ClientContext(HTTP:// yourserver /)){
context.Credentials =新的NetworkCredential(用户,密码,域) ;
名单列表= context.Web.Lists.GetByTitle(有些表);
context.ExecuteQuery();

//现在更新列表。
}


I need to write a small software which has to update some list on a Sharepoint 2010.

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.

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

I saw the possiblity 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?

Thank you!

解决方案

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

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