contentType:copyToDefaultContentLocation
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
将文件复制到内容类型中的默认 内容位置。 然后,可以通过 POST 操作将该文件添加为默认文件或模板。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Sites.ReadWrite.All、Sites.Manage.All、Sites.FullControl.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
Sites.ReadWrite.All、Sites.Manage.All、Sites.FullControl.All |
HTTP 请求
POST /sites/id/contentTypes/id/copyToDefaultContentLocation
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供参数的 JSON 表示形式。
下表显示了可用于此操作的参数。
| 参数 |
类型 |
说明 |
| sourceFile |
itemReference |
有关需要复制到默认内容位置的源文件的元数据。 必需。 |
| destinationFileName |
string |
目标文件名。 |
响应
如果成功,此调用将返回 响应 204 No Content 。
示例
请求
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"
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var sourceFile = new ItemReference
{
SharepointIds = new SharepointIds
{
ListId = "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0",
ListItemId = "2"
}
};
var destinationFileName = "newname.txt";
await graphClient.Sites["{site-id}"].ContentTypes["{contentType-id}"]
.CopyToDefaultContentLocation(sourceFile,destinationFileName)
.Request()
.PostAsync();
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);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/sites/{id}/contentTypes/{contentTypeId}/copyToDefaultContentLocation"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSMutableDictionary *payloadDictionary = [[NSMutableDictionary alloc] init];
MSGraphItemReference *sourceFile = [[MSGraphItemReference alloc] init];
MSGraphSharepointIds *sharepointIds = [[MSGraphSharepointIds alloc] init];
[sharepointIds setListId:@"e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0"];
[sharepointIds setListItemId:@"2"];
[sourceFile setSharepointIds:sharepointIds];
payloadDictionary[@"sourceFile"] = sourceFile;
NSString *destinationFileName = @"newname.txt";
payloadDictionary[@"destinationFileName"] = destinationFileName;
NSData *data = [NSJSONSerialization dataWithJSONObject:payloadDictionary options:kNilOptions error:&error];
[urlRequest setHTTPBody:data];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
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("{id}").contentTypes("{contentTypeId}")
.copyToDefaultContentLocation(ContentTypeCopyToDefaultContentLocationParameterSet
.newBuilder()
.withSourceFile(sourceFile)
.withDestinationFileName(destinationFileName)
.build())
.buildRequest()
.post();
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
sourceFile := msgraphsdk.NewItemReference()
requestBody.SetSourceFile(sourceFile)
sharepointIds := msgraphsdk.NewSharepointIds()
sourceFile.SetSharepointIds(sharepointIds)
listId := "e2ecf63b-b0fd-48f7-a54a-d8c15479e3b0"
sharepointIds.SetListId(&listId)
listItemId := "2"
sharepointIds.SetListItemId(&listItemId)
destinationFileName := "newname.txt"
requestBody.SetDestinationFileName(&destinationFileName)
siteId := "site-id"
contentTypeId := "contentType-id"
graphClient.SitesById(&siteId).ContentTypesById(&contentTypeId).CopyToDefaultContentLocation(site-id, contentType-id).Post(requestBody)
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
响应
HTTP/1.1 204 No Content