无法在列表中创建文件夹 [英] Cannot create a folder in a list

查看:68
本文介绍了无法在列表中创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在列表中创建一个文件夹,以下操作不起作用:

I am trying to create a folder in a list, the following does not work:

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

我将这些用作其他呼叫的参数,我可以保留它还是期望GUID?

I am using these as parameters for other calls, can I leave it be or does it expect GUID?

编辑1

错误引号是代码:

BadRequest
Message: Url specified is invalid.

因此,我假设.Sites.Lists应该具有GUID,但是用网站ID和列表ID替换网站URL后,我得到以下信息:

So I assume the .Sites and .Lists should have GUID but after replacing the Site URL with Id of site and ID of the list I get the following:

Code: -1, Microsoft.SharePoint.Client.ResourceNotFoundException
Message: Cannot find resource for the request Microsoft.FileServices.FileService/Sites('50cb05fa-27f9-45bf-a5f3-5f82e0e2eb00')/lists('ad52e785-c9b7-4106-af7b-a3394462875c')/drive/.

编辑2

我尝试通过Graph Explorer创建文件夹,在列表中找到该文件夹​​的内容类型ID,并使用POST

I have tried to create the folder via Graph Explorer, found the content type ID for the folder on a list and used POST https://graph.microsoft.com/v1.0/sites/50cb05fa-27f9-45bf-a5f3-5f82e0e2eb00/lists/ad52e785-c9b7-4106-af7b-a3394462875c/items

具有此请求正文

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

现在将创建文件夹,但呼叫需要标题,但不接受名称,这将导致创建的文件夹中没有名称(标题).它确实接受小写字母N的名称",但名称仍未显示在列表中.试图将其作为"BaseName","FileLeafRef"和Folder的其他一些内部名称发送,但没有成功.

Now the folder gets created, but the call requires Title, but does not accept Name, which results in created folder without Name (title). It does accept "name"with lowercase N, but still the name is not shown in the list. Tried to send it as "BaseName", "FileLeafRef" and some other internal names of Folder, but without success.

推荐答案

没有错误消息,目前尚不清楚发生了什么.也就是说,用于创建新文件夹的语法应如下所示:

Without an error message, it isn't clear exactly what is happening here. That said, the syntax for creating a new folder should look like this:

var folder = new DriveItem
{
    Name = plan.Title,
    Folder = new Folder { },
    @microsoft.graph.conflictBehavior = "rename"
};

这篇关于无法在列表中创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆