命名空间:microsoft.graph
重要
Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
异步创建 driveItem 的副本。 可以选择仅复制子项、指定新的父文件夹或提供新名称。 接受请求后,操作将排队并异步处理。 使用 监视器 URL 跟踪进度,直到操作完成。
复制操作限制为 30,000 个 driveItem。 有关详细信息,请参阅 SharePoint 限制。
重要
- 复制 driveItem 时不会保留元数据,包括系统元数据和自定义元数据。 而是在目标位置创建一个全新的 driveItem 。
- 仅当 includeAllVersionHistory 参数显式设置为
true时,才会保留文件版本。 否则,仅复制最新版本。
- 使用仅限应用的身份验证时,不支持跨地理复制。
- 如果还传递了名称请求参数,则忽略 includeAllVersionHistory 请求参数时会出现已知问题。 要避免此问题,请先在不使用 name 参数的情况下执行复制操作,然后在复制完成后重命名目标项。
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
✅ |
✅ |
✅ |
权限
注意
复制 driveItem 时不会保留权限。 复制的 driveItem 将继承目标文件夹的权限。
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
Files.ReadWrite |
Files.ReadWrite.All、Sites.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
Files.ReadWrite |
Files.ReadWrite.All |
| 应用程序 |
Files.ReadWrite.All |
Sites.ReadWrite.All |
注意
SharePoint Embedded 需要访问 FileStorageContainer.Selected 容器内容的权限。 此权限与前面提到的权限不同。 除了 Microsoft Graph 权限外,应用还必须具有调用此 API 所需的 容器类型权限 。 有关详细信息,请参阅 SharePoint Embedded 身份验证和授权。
HTTP 请求
POST /drives/{driveId}/items/{itemId}/copy
POST /groups/{groupId}/drive/items/{itemId}/copy
POST /me/drive/items/{item-id}/copy
POST /sites/{siteId}/drive/items/{itemId}/copy
POST /users/{userId}/drive/items/{itemId}/copy
可选的查询参数
此方法支持查询参数, @microsoft.graph.conflictBehavior 以便在发生冲突时自定义行为。
| 值 |
说明 |
| 失败 |
发生冲突时,整个操作将失败。 如果未指定任何选项,则此行为是默认行为。 |
| replace |
发生冲突时,将删除预先存在的文件项并将其替换为新项。 仅文件项支持此选项。 新项与旧项同名。 旧项的历史记录将被删除。 |
| rename |
将保证唯一性的最小整数追加到新文件或文件夹的名称并完成操作。 |
注意
OneDrive 使用者不支持此 conflictBehavior 参数。
该 @microsoft.graph.conflictBehavior 参数应用于操作期间复制的所有项。 仅文件支持该 replace 值;有冲突的文件夹将改用该 fail 行为。
请求正文
在请求正文中,提供具有以下参数的 JSON 对象。
| 名称 |
值 |
说明 |
| childrenOnly |
布尔值 |
可选。 如果设置为 true,则会复制 driveItem 的子项,但不会复制 driveItem 本身。 默认值为 false。
仅对文件夹项目有效。 |
| includeAllVersionHistory |
布尔值 |
可选。 如果设置为 true,则在目标版本设置限制内,源文件的版本历史记录 (主要版本和次要版本(如果应将任何) 复制到目标版本)。 如果 ,则 false仅将最新的主要版本复制到目标。 默认值为 false。 |
| name |
String |
可选。 副本的新名称。 如果未提供此信息,则使用与原始文件相同的名称。 |
| parentReference |
itemReference |
可选。 对在其中创建副本的父项的引用。 |
注意
parentReference 参数应包括目标文件夹的 driveId 和 id 参数。
响应
接受请求后,响应将返回有关如何 监视复制进度 的详细信息。 响应指示是接受还是拒绝复制操作;例如,如果目标文件名已在使用中。
示例
示例 1:将文件复制到文件夹
此示例演示如何将 标识的文件 {item-id} 复制到由 其 driveId 和 id 值标识的目标文件夹中。
为复制的文件赋予新名称 contoso plan (copy).txt。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"name": "contoso plan (copy).txt"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
Name = "contoso plan (copy).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}"].Copy.PostAsync(requestBody);
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewCopyPostRequestBody()
parentReference := graphmodels.NewItemReference()
driveId := "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
parentReference.SetDriveId(&driveId)
id := "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
name := "contoso plan (copy).txt"
requestBody.SetName(&name)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
copy, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Copy().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody copyPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody();
ItemReference parentReference = new ItemReference();
parentReference.setDriveId("b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop");
parentReference.setId("DCD0D3AD-8989-4F23-A5A2-2C086050513F");
copyPostRequestBody.setParentReference(parentReference);
copyPostRequestBody.setName("contoso plan (copy).txt");
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").copy().post(copyPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: 'b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
},
name: 'contoso plan (copy).txt'
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$requestBody->setName('contoso plan (copy).txt');
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
driveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
name = "contoso plan (copy).txt"
}
Copy-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.drives.item.items.item.copy.copy_post_request_body import CopyPostRequestBody
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 = CopyPostRequestBody(
parent_reference = ItemReference(
drive_id = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
),
name = "contoso plan (copy).txt",
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').copy.post(request_body)
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
使用标头中的 Location URL 监视异步复制操作的进度。
示例 2:复制文件夹中的子项
此示例仅将文件夹的内容(而不复制文件夹本身)到其他目标。 源文件夹由 {item-id}标识,目标文件夹由其 driveId 和 id 值标识。
请求将 childrenOnly 参数设置为 true,该参数仅在源项是文件夹时有效。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"childrenOnly": true
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
ChildrenOnly = true,
};
// 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}"].Copy.PostAsync(requestBody);
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewCopyPostRequestBody()
parentReference := graphmodels.NewItemReference()
driveId := "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
parentReference.SetDriveId(&driveId)
id := "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
childrenOnly := true
requestBody.SetChildrenOnly(&childrenOnly)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
copy, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Copy().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody copyPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody();
ItemReference parentReference = new ItemReference();
parentReference.setDriveId("b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop");
parentReference.setId("DCD0D3AD-8989-4F23-A5A2-2C086050513F");
copyPostRequestBody.setParentReference(parentReference);
copyPostRequestBody.setChildrenOnly(true);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").copy().post(copyPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: 'b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
},
childrenOnly: true
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$requestBody->setChildrenOnly(true);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
driveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
childrenOnly = $true
}
Copy-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.drives.item.items.item.copy.copy_post_request_body import CopyPostRequestBody
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 = CopyPostRequestBody(
parent_reference = ItemReference(
drive_id = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
),
children_only = True,
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').copy.post(request_body)
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
Location响应字段包含一个监控 URL,可用于检查复制操作的进度。 由于复制操作是异步发生的,并且可能在未指定的时间后完成,因此可以重复使用此 URL 来跟踪其状态。
要接收类似于以下示例中的状态报告,请获取响应字段中的 Location URL。
{
"@odata.context": "https://contoso.sharepoint.com/sites/site1/_api/v2.1/$metadata#drives('driveId')/operations/$entity",
"id": "049af13f-d177-4c70-aed0-eb6f04a5d88b",
"createdDateTime": "0001-01-01T00:00:00Z",
"lastActionDateTime": "0001-01-01T00:00:00Z",
"percentageComplete": 100,
"percentComplete": 100,
"resourceId": "016OGUCSF6Y2GOVW7725BZO354PWSELRRZ",
"resourceLocation": "https://contoso.sharepoint.com/sites/site2/_api/v2.0/drives/b!1YwGyNd6RUuVB42eCVw7ULlXybr_-09Br67iDGnYY-neBqwZd6jJRJbgCTx0On5n/items/016OGUCSF6Y2GOVW7725BZO354PWSELRRZ",
"status": "completed"
}
示例 3:由于目标文件夹中的名称冲突,复制失败
此示例显示尝试将文件复制到已包含相同名称的文件的目标文件夹失败的情况。 请求未指定 @microsoft.graph.conflictBehavior 用于解决冲突的查询参数。
由于未提供冲突行为,因此 API 接受请求,但在处理过程中失败。 操作返回错误 nameAlreadyExists 。
若要避免此错误,请使用值为 OR rename的 replace@microsoft.graph.conflictBehavior 参数。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
};
// 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}"].Copy.PostAsync(requestBody);
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewCopyPostRequestBody()
parentReference := graphmodels.NewItemReference()
driveId := "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
parentReference.SetDriveId(&driveId)
id := "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
copy, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Copy().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody copyPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody();
ItemReference parentReference = new ItemReference();
parentReference.setDriveId("b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop");
parentReference.setId("DCD0D3AD-8989-4F23-A5A2-2C086050513F");
copyPostRequestBody.setParentReference(parentReference);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").copy().post(copyPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: 'b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
}
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
driveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
}
Copy-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.drives.item.items.item.copy.copy_post_request_body import CopyPostRequestBody
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 = CopyPostRequestBody(
parent_reference = ItemReference(
drive_id = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
),
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').copy.post(request_body)
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
以下示例显示通过访问初始请求响应中字段值 Location 中的 URL 获取的示例状态报告。
{
"id": "46cf980a-28e1-4623-b8d0-11fc5278efe6",
"createdDateTime": "0001-01-01T00:00:00Z",
"lastActionDateTime": "0001-01-01T00:00:00Z",
"status": "failed",
"error": {
"code": "nameAlreadyExists",
"message": "Name already exists"
}
}
示例 4:将文件复制到包含同名文件的文件夹中
此示例演示如何将文件复制到已包含同名文件的文件夹中。 该请求使用 @microsoft.graph.conflictBehavior 查询参数来处理命名冲突。
参数设置为 replace,指示 API 覆盖目标文件夹中的现有项目。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy?@microsoft.graph.conflictBehavior=replace
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
};
// 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}"].Copy.PostAsync(requestBody, (requestConfiguration) =>
{
requestConfiguration.QueryParameters.@microsoft.graph.conflictBehavior = "replace";
});
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestMicrosoftGraphConflictBehavior := "replace"
requestParameters := &graphdrives.ItemItemsItemCopyRequestBuilderPostQueryParameters{
MicrosoftGraphConflictBehavior: &requestMicrosoftGraphConflictBehavior,
}
configuration := &graphdrives.ItemItemsItemCopyRequestBuilderPostRequestConfiguration{
QueryParameters: requestParameters,
}
requestBody := graphdrives.NewCopyPostRequestBody()
parentReference := graphmodels.NewItemReference()
driveId := "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
parentReference.SetDriveId(&driveId)
id := "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
copy, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Copy().Post(context.Background(), requestBody, configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody copyPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody();
ItemReference parentReference = new ItemReference();
parentReference.setDriveId("b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop");
parentReference.setId("DCD0D3AD-8989-4F23-A5A2-2C086050513F");
copyPostRequestBody.setParentReference(parentReference);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").copy().post(copyPostRequestBody, requestConfiguration -> {
requestConfiguration.queryParameters.@microsoft.graph.conflictBehavior = "replace";
});
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: 'b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
}
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$requestConfiguration = new CopyRequestBuilderPostRequestConfiguration();
$queryParameters = CopyRequestBuilderPostRequestConfiguration::createQueryParameters();
$queryParameters->@microsoftgraphconflictBehavior = "replace";
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody, $requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
driveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
}
Copy-MgBetaDriveItem -DriveId $driveId -DriveItemId $driveItemId -@microsoft.graph.conflictbehavior "replace" -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.drives.item.items.item.copy.copy_request_builder import CopyRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph_beta.generated.drives.item.items.item.copy.copy_post_request_body import CopyPostRequestBody
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 = CopyPostRequestBody(
parent_reference = ItemReference(
drive_id = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
),
)
query_params = CopyRequestBuilder.CopyRequestBuilderPostQueryParameters(
@microsoft_graph_conflict_behavior = "replace",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').copy.post(request_body, request_configuration = request_configuration)
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
示例 5:使用 Windows 复制具有文件夹冲突的子项时,请求无效 conflictBehavior=replace
此示例显示尝试仅复制文件夹的子项的失败请求。 请求将 childrenOnly 参数 true 设置为,并使用 @microsoft.graph.conflictBehavior 值 replace为 .
源文件夹中的一个或多个子项是文件夹。 因为当冲突项是文件夹时不支持此 replace 行为,所以复制操作失败。 接受请求并返回监视 URL,但该操作最终会报告错误。
复制包含文件夹的子项时,请使用 rename or fail 代替 replace 。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy?@microsoft.graph.conflictBehavior=replace
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"childrenOnly": true
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
ChildrenOnly = true,
};
// 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}"].Copy.PostAsync(requestBody, (requestConfiguration) =>
{
requestConfiguration.QueryParameters.@microsoft.graph.conflictBehavior = "replace";
});
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestMicrosoftGraphConflictBehavior := "replace"
requestParameters := &graphdrives.ItemItemsItemCopyRequestBuilderPostQueryParameters{
MicrosoftGraphConflictBehavior: &requestMicrosoftGraphConflictBehavior,
}
configuration := &graphdrives.ItemItemsItemCopyRequestBuilderPostRequestConfiguration{
QueryParameters: requestParameters,
}
requestBody := graphdrives.NewCopyPostRequestBody()
parentReference := graphmodels.NewItemReference()
driveId := "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
parentReference.SetDriveId(&driveId)
id := "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
childrenOnly := true
requestBody.SetChildrenOnly(&childrenOnly)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
copy, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Copy().Post(context.Background(), requestBody, configuration)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody copyPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody();
ItemReference parentReference = new ItemReference();
parentReference.setDriveId("b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop");
parentReference.setId("DCD0D3AD-8989-4F23-A5A2-2C086050513F");
copyPostRequestBody.setParentReference(parentReference);
copyPostRequestBody.setChildrenOnly(true);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").copy().post(copyPostRequestBody, requestConfiguration -> {
requestConfiguration.queryParameters.@microsoft.graph.conflictBehavior = "replace";
});
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: 'b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
},
childrenOnly: true
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyRequestBuilderPostRequestConfiguration;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$requestBody->setChildrenOnly(true);
$requestConfiguration = new CopyRequestBuilderPostRequestConfiguration();
$queryParameters = CopyRequestBuilderPostRequestConfiguration::createQueryParameters();
$queryParameters->@microsoftgraphconflictBehavior = "replace";
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody, $requestConfiguration)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
driveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
childrenOnly = $true
}
Copy-MgBetaDriveItem -DriveId $driveId -DriveItemId $driveItemId -@microsoft.graph.conflictbehavior "replace" -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.drives.item.items.item.copy.copy_request_builder import CopyRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
from msgraph_beta.generated.drives.item.items.item.copy.copy_post_request_body import CopyPostRequestBody
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 = CopyPostRequestBody(
parent_reference = ItemReference(
drive_id = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
),
children_only = True,
)
query_params = CopyRequestBuilder.CopyRequestBuilderPostQueryParameters(
@microsoft_graph_conflict_behavior = "replace",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').copy.post(request_body, request_configuration = request_configuration)
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
查询位置标头中的监视器 URL 以监视操作的状态。 失败的操作可能返回与以下示例类似的响应。
{
"@odata.context": "https://contoso.sharepoint.com/sites/site2/_api/v2.1/$metadata#drives('driveId')/operations/$entity",
"id": "e410fb22-fc84-41df-ac9f-e95e5110a5cb",
"createdDateTime": "0001-01-01T00:00:00Z",
"lastActionDateTime": "0001-01-01T00:00:00Z",
"status": "failed",
"error": {
"message": "Errors occurred during copy/move operation.",
"details": [
{
"code": "nameAlreadyExists",
"message": "Name already exists"
},
{
"code": "nameAlreadyExists",
"message": "Name already exists"
},
{
"code": "nameAlreadyExists",
"message": "Name already exists",
"target": "01E4CGZM4FGUVRMKSJWBCLZQTWNFGHOTXG"
},
{
"code": "nameAlreadyExists",
"message": "Name already exists",
"target": "01E4CGZM2XRHETBOUOYVA2OKZFMGGBQ6VU"
}
]
}
}
示例 6:复制项目并保留版本历史记录
此示例演示如何将文件项复制到新位置,并在复制的项中包含其版本历史记录。 该 includeAllVersionHistory 参数在请求正文中设置为 true 指示应保留版本历史记录。
如果源文件的版本数超过目标站点允许的版本数,则最初复制所有版本,然后在版本超过应用设置时遵循 版本存储行为 。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"includeAllVersionHistory": true
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.Copy;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
IncludeAllVersionHistory = true,
};
// 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}"].Copy.PostAsync(requestBody);
// 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"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewCopyPostRequestBody()
parentReference := graphmodels.NewItemReference()
driveId := "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
parentReference.SetDriveId(&driveId)
id := "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
parentReference.SetId(&id)
requestBody.SetParentReference(parentReference)
includeAllVersionHistory := true
requestBody.SetIncludeAllVersionHistory(&includeAllVersionHistory)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
copy, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Copy().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody copyPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.copy.CopyPostRequestBody();
ItemReference parentReference = new ItemReference();
parentReference.setDriveId("b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop");
parentReference.setId("DCD0D3AD-8989-4F23-A5A2-2C086050513F");
copyPostRequestBody.setParentReference(parentReference);
copyPostRequestBody.setIncludeAllVersionHistory(true);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").copy().post(copyPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const driveItem = {
parentReference: {
driveId: 'b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop',
id: 'DCD0D3AD-8989-4F23-A5A2-2C086050513F'
},
includeAllVersionHistory: true
};
await client.api('/me/drive/items/{item-id}/copy')
.version('beta')
.post(driveItem);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$requestBody->setIncludeAllVersionHistory(true);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
parentReference = @{
driveId = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop"
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
includeAllVersionHistory = $true
}
Copy-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.drives.item.items.item.copy.copy_post_request_body import CopyPostRequestBody
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 = CopyPostRequestBody(
parent_reference = ItemReference(
drive_id = "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
),
include_all_version_history = True,
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').copy.post(request_body)
响应
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/4A3407B5-88FC-4504-8B21-0AABD3412717
使用 Location 响应标头中的 URL 监视异步复制操作的进度。
示例 7:在没有复制根文件夹的情况下复制根文件夹时,请求无效 childrenOnly
此示例显示了一个失败的请求,该请求尝试通过指定 root 为 {item-id}. 请求不包含参数 childrenOnly 。 由于无法复制根文件夹本身,并且 childrenOnly 未设置为 true,因此请求将被拒绝并 invalidRequest 显示错误。
要复制根文件夹的内容而不复制文件夹本身,请将参数true设置为 childrenOnly 。
请求
POST https://graph.microsoft.com/beta/me/drive/items/root/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
}
}
响应
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 283
{
"error":
{
"code": "invalidRequest",
"message": "Cannot copy the root folder.",
"innerError":
{
"date": "2023-12-11T04:26:35",
"request-id": "8f897345980-f6f3-49dd-83a8-a3064eeecdf8",
"client-request-id": "50a0er33-4567-3f6c-01bf-04d144fc8bbe"
}
}
}
要解决此错误,请将此参数设置为 childrenOnly true。
示例 8:复制文件的子项时请求无效
此示例显示了一个失败的 childrenOnly 请求,该请求将参数 true 设置为源项(即文件)。 该 childrenOnly 参数仅对文件夹项有效。 由于文件不包含子项,因此请求将被拒绝并出现 invalidRequest 错误。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"childrenOnly": true
}
响应
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 290
{
"error":
{
"code": "invalidRequest",
"message": "childrenOnly option is not valid for file items.",
"innerError":
{
"date": "2023-12-11T04:26:35",
"request-id": "8f897345980-f6f3-49dd-83a8-a3064eeecdf8",
"client-request-id": "50a0er33-4567-3f6c-01bf-04d144fc8bbe""
}
}
}
示例 9:同时指定 and 时请求 childrenOnly 无效 name
此示例显示了一个失败的请求,该请求将 childrenOnly 参数 true 设置为仅复制文件夹的子项,同时还指定了一个新 name 值。 这两个参数不能一起使用,因为不会复制文件夹本身。 请求被拒绝并显示 invalidRequest 错误。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"name": "contoso plan (copy).txt",
"childrenOnly": true
}
响应
以下示例显示了相应的响应。
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 285
{
"error":
{
"code": "invalidRequest",
"message": "Cannot use name parameter alongside childrenOnly.",
"innerError":
{
"date": "2023-12-11T04:26:35",
"request-id": "8f897345980-f6f3-49dd-83a8-a3064eeecdf8",
"client-request-id": "50a0er33-4567-3f6c-01bf-04d144fc8bbe""
}
}
}
示例 10:成功的仅限儿童复制
此示例演示如何复制文件夹 (的子项,而无需将文件夹本身复制到新的目标) 。 源文件夹由 标识, {item-id}目标文件夹使用其 driveId 和 id指定。 请求将 childrenOnly 属性设置为 ,该属性 true仅对文件夹项有效。
请求
POST https://graph.microsoft.com/beta/me/drive/items/{item-id}/copy
Content-Type: application/json
{
"parentReference": {
"driveId": "b!s8RqPCGh0ESQS2EYnKM0IKS3lM7GxjdAviiob7oc5pXv_0LiL-62Qq3IXyrXnEop",
"id": "DCD0D3AD-8989-4F23-A5A2-2C086050513F"
},
"childrenOnly": true
}
响应
使用位置 URL 跟踪异步复制操作的状态。 成功的响应可能如下所示:
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/sites/FromSite/_api/v2.1/monitor/780293e6-07b3-4544-a126-fea909efcc84
{
"@odata.context": "https://contoso.sharepoint.com/sites/FromSite/_api/v2.1/$metadata#drives('b!eUKtdpCU_kSVaTUFV6NpD-X6ybrlZ_5AgIz5YS9EUgU51UBlz4oFSauS0JyHnBdR')/operations/$entity",
"id": "780293e6-07b3-4544-a126-fea909efcc84",
"createdDateTime": "0001-01-01T00:00:00Z",
"lastActionDateTime": "0001-01-01T00:00:00Z",
"percentageComplete": 100,
"percentComplete": 100,
"resourceId": "01MXEZFVE5G2AS5Y74YZFYQF3KZAQ7CFEP",
"resourceLocation": "https://contoso.sharepoint.com/sites/ToSite/_api/v2.0/drives/b!JiheeiHiFEymg-TwftZJ-eX6ybrlZ_5AgIz5YS9EUgU51UBlz4oFSauS0JyHnBdR/items/01MXEZFVE5G2AS5Y74YZFYQF3KZAQ7CFEP",
"status": "completed"
}
相关内容
有关错误信息,请参阅错误响应。