首页 > 解决方案 > 将项目添加到 SharePoint Online 列表 c#

问题描述

我有一个 web api,它的主体中有一些数据,并且我想使用 c# 添加到 SharePoint 在线列表中。但是下面的代码给了我 unauth 错误。

using (var context = new ClientContext(siteUrl))
{
    context.ExecutingWebRequest += Context_ExecutingWebRequest; // for oAuth it working in get list dat
    Web web = context.Web;  

    List topicsList = context.Web.Lists.GetByTitle("ListName");
    ListItemCreationInformation newTopicInfo = new ListItemCreationInformation();
    ListItem oListItem = topicsList.AddItem(newTopicInfo);                  

    oListItem["Title"] = "Test";
    oListItem["Column1"] = "Test1";                                    
    oListItem.Update();

    context.ExecuteQuery();
}

标签: c#asp.net-web-apisharepoint-onlinecsom

解决方案


上面的代码现在工作得很好,我缺少对我的应用程序的权限。要使用 oAuth,我们必须在 SharePoint 中注册一个加载项,并且要在 sharepoint 中发布数据,我必须将 FullControl 授予我的加载项,但在创建时我已将其设为只读。下面是参考。 参考


推荐阅读