无法在SharePoint Online列表中创建文件夹

时间:2019-08-01 09:43:08

标签: c# microsoft-graph sharepoint-online microsoft-graph-sdks

上一个问题:here被我们的英雄和讨厌的主持人关闭,他们急忙将所有内容标记为错误,但是一旦您对其进行编辑以满足他们的异常需要,就没有人投票重新打开它,因为他们已经做了自己的工作...

因此,请有人可以向我解释如何在SharePoint Online列表中正确创建文件夹吗?

我尝试首先使用C#SDK创建它,但该方法无效。

var folder = new DriveItem
{
Name = plan.Title,
Folder = new Folder()
};

await graphServiceClient
.Sites["ourdomain.sharepoint.com:/sites/ITOddeleni:"]
.Lists["Planner"]
.Drive
.Root
.Children
.Request()
.AddAsync(folder);

然后,我开始使用Graph Explorer,找到该文件夹​​的ContentType ID,并尝试将其创建为具有指定ContentType的项目。

这是JSON请求标头,它导致在列表中创建文件夹,但是没有名称,因为文件夹在SharePoint中的行为与项目不同。

{
"Title" : "Test2",
"contentType": { "id": "0x012000FC4989A03C9F7845AD8C206E2F47A0FD" }
}

我试图将“名称”,“ FileLeafRef”的“标题”更改为“标题”的Folders内部名称,但无法弄清楚。它接受了所有请求标头,但是创建的文件夹的名称仍然为空。

感谢您的帮助。

enter image description here

编辑:

我尝试了Vadim的建议,并且确实创建了该文件夹,乍一看,它带有您在代码中指定的名称。但它也带有一些生成的名称,请参见图片的右侧。

See the created folder

打开文件夹后,将释放名称,直到刷新文件夹所在级别的页面。这是打开文件夹时的外观。

enter image description here

我还试图在标题之外添加名称/名称,但是它返回 小写和大写“消息:字段'名称'均无法识别”。

2 个答案:

答案 0 :(得分:0)

您是否考虑过CSOM还是没有选择? SharePoint Online最佳选择是使用CSOM PnP nuget link

代码应如下所示:


    try
    {
        string siteUrl = "SiteUrl";
        AuthenticationManager authManager = new AuthenticationManager();
        using (ClientContext context = authManager.GetWebLoginClientContext(siteUrl))
        {
            List list = context.Web.Lists.GetByTitle("LibName");
            context.Load(list);
            context.ExecuteQuery();
            Folder folder = list.RootFolder.CreateFolder("NewFolder");
        }
    }
    catch (Exception ex)
    {
        // log error
        throw;
    }

我已经使用一些控制台应用程序测试了上面的代码,以我为例,结果是 enter image description here

我希望这会有所帮助:)

答案 1 :(得分:0)

似乎可以通过Create item endpoint来创建 List 中的文件夹,如下所示:

POST https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items
Content-Type: application/json

{
  "fields": {
    "Title": "Folder name goes here",
  },
  "contentType": { "id": "0x0120" }
}

其中

  • 诸如“标题”之类的文件夹属性是通过ListItem.Fields property
  • 指定的
  • 要创建文件夹类型的项目,需要明确指定设置为contentType的{​​{1}}属性

C#示例

0x0120
相关问题