简体   繁体   English

使用客户端对象模型在线访问SharePoint-禁止的错误

[英]Access SharePoint online using client object model- Forbidden error

I tried to Create a new list item using client object model. 我尝试使用客户端对象模型创建新的列表项。 I have created an asp.net application to do the task. 我创建了一个asp.net应用程序来执行此任务。 It works if I pass the URL of SharePoint server which is installed in my machine. 如果我传递了安装在计算机中的SharePoint服务器的URL,则它可以工作。 But if I give my SharePoint online URL it is not working as below code shows. 但是,如果我提供我的SharePoint在线URL,它将无法正常工作,如下面的代码所示。 I get "The remote server returned an error: (403) Forbidden. " error. 我收到“远程服务器返回错误:(403)禁止。”错误。 Any idea? 任何想法?

ClientContext context = new ClientContext("https://xxx.sharepoint.com/SitePages/");
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = result.City;
newItem["Body"] = result.State;
newItem.Update();
context.ExecuteQuery();

if you are trying to get a Context object from SharePoint Online you have to put in the right Credentials , as for SharePoint Online you should use the SharePointOnlineCredentials Class 如果您尝试从SharePoint Online获取上下文对象,则必须输入正确的Credentials ,对于SharePoint Online,则应使用SharePointOnlineCredentials类

A possible Authentication Method can be look like this: 可能的身份验证方法如下所示:

private void AutheticateO365(string url, string password, string userName)
{
   Context = new ClientContext(url);
   var passWord = new SecureString();
   foreach (char c in password.ToCharArray()) passWord.AppendChar(c);
   Context.Credentials = new SharePointOnlineCredentials(userName, passWord);
   var web = Context.Web;
   Context.Load(web);
   Context.ExecuteQuery();
}

I would imagine you just have to supply your login credentials and it should work: 我想您只需提供登录凭据即可,它应该可以工作:

clientContext.Credentials = new NetworkCredential("Username", "Password", "Domain");

You'll need to including System.Net: 您需要包括System.Net:

using System.Net;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试使用SharePoint Client Object Model和.NET应用程序在线连接共享点时出现“提供了无效的参数”错误 - “An invalid argument was supplied” error when I try to connect sharepoint online using SharePoint Client Object Model with .NET application 使用 c# 和客户端对象模型 (CSOM) 使用外部用户连接到 SharePoint Online - Connect to SharePoint Online using an external user using c# and Client Side Object Model (CSOM) 通过客户端对象模型中的代理服务器连接到SharePoint Online - Connect to SharePoint Online via proxy server in Client Object Model 使用客户端对象模型(CSOM)将多个用户添加到SharePoint Online文档库项目“人员或组”列 - Add multiple users to SharePoint Online document library item “Person or Group” column using Client Side Object Model (CSOM) 验证网络凭据以访问客户端对象模型上的SharePoint站点 - Authenticate network credential to access SharePoint site on client object model Sharepoint客户端对象模型区域设置 - Sharepoint Client Object Model locale 使用共享点对象模型创建新的共享点站点时出错 - Error while creating a new sharepoint site using sharepoint object model 使用客户端对象模型在SharePoint文档库上创建文件夹 - Create folder on SharePoint document library using client object model 使用Sharepoint客户端对象模型添加现有的WebPart - Add an existing WebPart Using the Sharepoint client object Model 使用客户端对象模型将数据从Sharepoint绑定到下拉列表 - Databind to dropdownlist from Sharepoint using client object model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM