Cannot create a folder in a list [closed]

非 Y 不嫁゛ 提交于 2019-12-13 16:07:28

问题


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

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

EDIT 1

The ERROR quote is Code:

BadRequest
Message: Url specified is invalid.

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/.

EDIT 2

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

With this Request body

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

Now the folder gets created, but the call requires Title, but does not accept Name, which results in created folder without Name (title). Edit: 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.


回答1:


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"
};


来源:https://stackoverflow.com/questions/57185537/cannot-create-a-folder-in-a-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!