contentType: copyToDefaultContentLocation
Article
05/17/2023
5 contributors
Feedback
In this article
Namespace: microsoft.graph
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.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Sites.ReadWrite.All, Sites.Manage.All, Sites.FullControl.All
Delegated (personal Microsoft account)
Not supported.
Application
Sites.ReadWrite.All, Sites.Manage.All, Sites.FullControl.All
HTTP request
POST /sites/{siteId}/contentTypes/{contentTypeId}/copyToDefaultContentLocation
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
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/v1.0/sites/{siteId}/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
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new Microsoft.Graph.Sites.Item.ContentTypes.Item.CopyToDefaultContentLocation.CopyToDefaultContentLocationPostRequestBody
{
SourceFile = new ItemReference
{
SharepointIds = new SharepointIds
{
ListId = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0",
ListItemId = "2",
},
},
DestinationFileName = "newname.txt",
};
await graphClient.Sites["{site-id}"].ContentTypes["{contentType-id}"].CopyToDefaultContentLocation.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/Sites/Item/ContentTypes/Item/CopyToDefaultContentLocation"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.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)
graphClient.Sites().BySiteId("site-id").ContentTypes().ByContentTypeId("contentType-id").CopyToDefaultContentLocation().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
ItemReference sourceFile = new ItemReference();
SharepointIds sharepointIds = new SharepointIds();
sharepointIds.listId = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0";
sharepointIds.listItemId = "2";
sourceFile.sharepointIds = sharepointIds;
String destinationFileName = "newname.txt";
graphClient.sites("{siteId}").contentTypes("{contentTypeId}")
.copyToDefaultContentLocation(ContentTypeCopyToDefaultContentLocationParameterSet
.newBuilder()
.withSourceFile(sourceFile)
.withDestinationFileName(destinationFileName)
.build())
.buildRequest()
.post();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
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/{siteId}/contentTypes/{contentTypeId}/copyToDefaultContentLocation')
.post(copyToDefaultContentLocation);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$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);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Sites
$params = @{
sourceFile = @{
sharepointIds = @{
listId = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0"
listItemId = "2"
}
}
destinationFileName = "newname.txt"
}
Copy-MgSiteContentTypeToDefaultContentLocation -SiteId $siteId -ContentTypeId $contentTypeId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
HTTP/1.1 204 No Content