Namespace: microsoft.graph
Important
APIs under the /beta version in Microsoft Graph are subject to change. Use of these APIs in production applications is not supported. To determine whether an API is available in v1.0, use the Version selector.
Copy a file to a default content location in a content type. The file can then be added as a default file or template via a POST operation.
This API is available in the following national cloud deployments.
| Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
| ✅ |
✅ |
✅ |
✅ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
| Permission type |
Least privileged permissions |
Higher privileged permissions |
| Delegated (work or school account) |
Sites.ReadWrite.All |
Sites.FullControl.All, Sites.Manage.All |
| Delegated (personal Microsoft account) |
Not supported. |
Not supported. |
| Application |
Sites.ReadWrite.All |
Sites.FullControl.All, Sites.Manage.All |
HTTP request
POST /sites/{siteId}/contentTypes/{contentTypeId}/copyToDefaultContentLocation
Request body
In the request body, supply a JSON representation of the parameters.
The following table shows the parameters that can be used with this action.
| Parameter |
Type |
Description |
| sourceFile |
itemReference |
Metadata about the source file that needs to be copied to the default content location. Required. |
| destinationFileName |
string |
Destination filename. |
Response
If successful, this call returns a 204 No Content response.
Example
Request
POST https://graph.microsoft.com/beta/sites/{id}/contentTypes/{contentTypeId}/copyToDefaultContentLocation
Content-Type: application/json
{
"sourceFile":{
"sharepointIds":{
"listId":"e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0",
"listItemId":"2"
}
},
"destinationFileName":"newname.txt"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Sites.Item.ContentTypes.Item.CopyToDefaultContentLocation;
using Microsoft.Graph.Beta.Models;
var requestBody = new CopyToDefaultContentLocationPostRequestBody
{
SourceFile = new ItemReference
{
SharepointIds = new SharepointIds
{
ListId = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0",
ListItemId = "2",
},
},
DestinationFileName = "newname.txt",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Sites["{site-id}"].ContentTypes["{contentType-id}"].CopyToDefaultContentLocation.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"
graphsites "github.com/microsoftgraph/msgraph-beta-sdk-go/sites"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphsites.NewCopyToDefaultContentLocationPostRequestBody()
sourceFile := graphmodels.NewItemReference()
sharepointIds := graphmodels.NewSharepointIds()
listId := "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0"
sharepointIds.SetListId(&listId)
listItemId := "2"
sharepointIds.SetListItemId(&listItemId)
sourceFile.SetSharepointIds(sharepointIds)
requestBody.SetSourceFile(sourceFile)
destinationFileName := "newname.txt"
requestBody.SetDestinationFileName(&destinationFileName)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Sites().BySiteId("site-id").ContentTypes().ByContentTypeId("contentType-id").CopyToDefaultContentLocation().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.sites.item.contenttypes.item.copytodefaultcontentlocation.CopyToDefaultContentLocationPostRequestBody copyToDefaultContentLocationPostRequestBody = new com.microsoft.graph.beta.sites.item.contenttypes.item.copytodefaultcontentlocation.CopyToDefaultContentLocationPostRequestBody();
ItemReference sourceFile = new ItemReference();
SharepointIds sharepointIds = new SharepointIds();
sharepointIds.setListId("e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0");
sharepointIds.setListItemId("2");
sourceFile.setSharepointIds(sharepointIds);
copyToDefaultContentLocationPostRequestBody.setSourceFile(sourceFile);
copyToDefaultContentLocationPostRequestBody.setDestinationFileName("newname.txt");
graphClient.sites().bySiteId("{site-id}").contentTypes().byContentTypeId("{contentType-id}").copyToDefaultContentLocation().post(copyToDefaultContentLocationPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const copyToDefaultContentLocation = {
sourceFile: {
sharepointIds: {
listId: 'e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0',
listItemId: '2'
}
},
destinationFileName: 'newname.txt'
};
await client.api('/sites/{id}/contentTypes/{contentTypeId}/copyToDefaultContentLocation')
.version('beta')
.post(copyToDefaultContentLocation);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Sites\Item\ContentTypes\Item\CopyToDefaultContentLocation\CopyToDefaultContentLocationPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\ItemReference;
use Microsoft\Graph\Beta\Generated\Models\SharepointIds;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CopyToDefaultContentLocationPostRequestBody();
$sourceFile = new ItemReference();
$sourceFileSharepointIds = new SharepointIds();
$sourceFileSharepointIds->setListId('e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0');
$sourceFileSharepointIds->setListItemId('2');
$sourceFile->setSharepointIds($sourceFileSharepointIds);
$requestBody->setSourceFile($sourceFile);
$requestBody->setDestinationFileName('newname.txt');
$graphServiceClient->sites()->bySiteId('site-id')->contentTypes()->byContentTypeId('contentType-id')->copyToDefaultContentLocation()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Sites
$params = @{
sourceFile = @{
sharepointIds = @{
listId = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0"
listItemId = "2"
}
}
destinationFileName = "newname.txt"
}
Copy-MgBetaSiteContentTypeToDefaultContentLocation -SiteId $siteId -ContentTypeId $contentTypeId -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.sites.item.contenttypes.item.copy_to_default_content_location.copy_to_default_content_location_post_request_body import CopyToDefaultContentLocationPostRequestBody
from msgraph_beta.generated.models.item_reference import ItemReference
from msgraph_beta.generated.models.sharepoint_ids import SharepointIds
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CopyToDefaultContentLocationPostRequestBody(
source_file = ItemReference(
sharepoint_ids = SharepointIds(
list_id = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0",
list_item_id = "2",
),
),
destination_file_name = "newname.txt",
)
await graph_client.sites.by_site_id('site-id').content_types.by_content_type_id('contentType-id').copy_to_default_content_location.post(request_body)
Response
HTTP/1.1 204 No Content