当前位置: 首页 > 编程语言 > C#

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

时间:2023-04-10 16:22:47 C#

使用客户端对象模型在线访问SharePoint-禁止错误我正在尝试使用客户端对象模型创建一个新的列表项。我创建了一个asp.net应用程序来完成任务。如果我传递安装在我的计算机中的SharePoint服务器的URL,它就会起作用。但是,如果我提供我的SharePointOnlineURL,它将不起作用,如下面的代码所示。我收到“远程服务器返回错误:(403)禁止访问。”错误。有任何想法吗?ClientContextcontext=newClientContext("https://xxx.sharepoint.com/SitePages/");列表announcementsList=context.Web.Lists.GetByTitle("Announcements");ListItemCreationInformationitemCreateInfo=newListItemCreationInformation();Microsoft.SharePoint。Client.ListItemnewItem=announcementsList.AddItem(itemCreateInfo);newItem["标题"]=result.City;newItem["Body"]=result.State;新项目.更新();context.ExecuteQuery();SharePointOnline获取上下文对象,您必须输入正确的凭据,对于SharePointOnline,您应该使用SharePointOnlineCredentials类可能的身份验证方法可能如下所示:privatevoidAuthenticateO365(stringurl,stringpassword,stringuserName){Context=new客户端上下文(网址);varpassWord=newSecureString();foreach(charcinpassword.ToCharArray())passWord.AppendChar(c);Context.Credentials=newSharePointOnlineCredentials(userName,passWord);varweb=Context.Web;上下文.Load(网络);上下文.ExecuteQuery();我认为你只需要提供你的登录凭据就可以了:clientContext.Credentials=newNetworkCredential("用户名","密码","域");需要包含System.Net:以上就是《C#学习教程:使用客户端对象模型在线访问SharePoint——禁止误传》的全部内容,如果对你有用,需要进一步了解C#学习教程,我希望大家多多关注——使用System.Net;明源: