命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
将 driveItem 移动到新的父级。
若要将 driveItem 移动到新的父项,你的应用请求对要移动的 driveItem 的 parentReference 的更新。 移动是一种特殊类型的 更新 操作。
你的应用程序可以将以下操作组合到单个请求中:将项目移动到新的容器和更新项目的其他属性。
在同一站点或容器中移动 driveItem 时,所有现有共享链接将继续工作。 如果将 driveItem 移动到其他站点或容器,则现有共享链接不再有效。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Files.ReadWrite |
Files.ReadWrite.All、Sites.ReadWrite.All |
委派(个人 Microsoft 帐户) |
Files.ReadWrite |
Files.ReadWrite.All |
应用程序 |
Files.ReadWrite.All |
Sites.ReadWrite.All |
HTTP 请求
PATCH /drives/{drive-id}/items/{item-id}
PATCH /groups/{group-id}/drive/items/{item-id}
PATCH /me/drive/items/{item-id}
PATCH /sites/{site-id}/drive/items/{item-id}
PATCH /users/{user-id}/drive/items/{item-id}
名称 |
类型 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
|
if-match |
String |
如果包含此请求标头,并且提供的 eTag (或 cTag) 与文件夹上的当前 eTag 不匹配, 412 Precondition Failed 则会返回响应。 可选。 |
请求正文
在请求正文中,提供 parentReference 属性的新值。
请求正文中未包含的现有属性会保留其以前的值,或者根据对其他属性值的更改重新计算属性。
为了获得最佳性能,请仅包括更改的值,并省略未更改的值。
注意
将项移动到驱动器的根目录时,应用程序必须使用根文件夹的实际 ID 作为父引用,而不是 "id: root"
语法。
响应
如果成功,此方法在响应正文中返回响应 200 OK
代码和更新的 driveItem 资源。
有关如何返回错误的信息,请参阅 错误响应。
示例
请求
以下示例将 指定的 {item-id}
项移动到 ID new-parent-folder-id
为 的用户驱动器中的文件夹中。
PATCH https://graph.microsoft.com/beta/me/drive/items/{item-id}
Content-type: application/json
{
"parentReference": {
"id": "new-parent-folder-id"
},
"name": "new-item-name.txt"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new DriveItem
{
ParentReference = new ItemReference
{
Id = "new-parent-folder-id",
},
Name = "new-item-name.txt",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].PatchAsync(requestBody);
mgc-beta drives items patch --drive-id {drive-id} --drive-item-id {driveItem-id} --body '{\
"parentReference": {\
"id": "new-parent-folder-id"\
},\
"name": "new-item-name.txt"\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDriveItem()
parentReference := graphmodels.NewItemReference()
id := "new-parent-folder-id"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
name := "new-item-name.txt"
requestBody.SetName(&name)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
items, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
DriveItem driveItem = new DriveItem();
ItemReference parentReference = new ItemReference();
parentReference.setId("new-parent-folder-id");
driveItem.setParentReference(parentReference);
driveItem.setName("new-item-name.txt");
DriveItem result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").patch(driveItem);
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
id: 'new-parent-folder-id'
},
name: 'new-item-name.txt'
};
await client.api('/me/drive/items/{item-id}')
.version('beta')
.update(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\DriveItem;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new DriveItem();
$parentReference = new ItemReference();
$parentReference->setId('new-parent-folder-id');
$requestBody->setParentReference($parentReference);
$requestBody->setName('new-item-name.txt');
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
id = "new-parent-folder-id"
}
name = "new-item-name.txt"
}
Update-MgBetaDriveItem -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.drive_item import DriveItem
from msgraph_beta.generated.models.item_reference import ItemReference
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = DriveItem(
parent_reference = ItemReference(
id = "new-parent-folder-id",
),
name = "new-item-name.txt",
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').patch(request_body)
响应
以下示例显示了对此移动请求的响应。
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "0123456789abc",
"name": "new-item-name.txt",
"parentReference":
{
"driveId": "11231001",
"path": "/drive/root:/Documents",
"id": "1231203102!1011"
}
}