你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

IDocumentClient.ReplaceAttachmentAsync 方法

定义

重载

ReplaceAttachmentAsync(Attachment, RequestOptions, CancellationToken)

Attachment Azure Cosmos DB 服务中的 替换为异步操作。

ReplaceAttachmentAsync(Uri, Attachment, RequestOptions, CancellationToken)

将附件替换为 Azure Cosmos DB 服务中的异步操作。

ReplaceAttachmentAsync(Attachment, RequestOptions, CancellationToken)

Attachment Azure Cosmos DB 服务中的 替换为异步操作。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> ReplaceAttachmentAsync (Microsoft.Azure.Documents.Attachment attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceAttachmentAsync : Microsoft.Azure.Documents.Attachment * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function ReplaceAttachmentAsync (attachment As Attachment, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

attachment
Attachment

已更新 Attachment ,以将现有资源替换为 。

options
RequestOptions

(可选) 请求的请求选项。

cancellationToken
CancellationToken

(可选) A CancellationToken ,可供其他对象或线程用来接收取消通知。

返回

System.Threading.Tasks 个 , ResourceResponse<TResource> 它包含包装 Attachment 包含更新的资源记录的 。

例外

如果未 attachment 设置 。

此异常可以封装许多不同类型的错误。 若要确定特定错误,请始终查看 StatusCode 属性。 创建文档时可能会获取的一些常见代码包括:

StatusCode异常原因
404NotFound - 这意味着你尝试删除的资源不存在。

示例

//Fetch the item to be updated
Attachment attachment = client.CreateAttachmentQuery(attachmentLink)
                            .Where(r => r.Id == "attachment id")
                            .AsEnumerable()
                            .SingleOrDefault();

//Update some properties on the found resource
attachment.MediaLink = "updated value";

//Now persist these changes to the database by replacing the original resource
Attachment updated = await client.ReplaceAttachmentAsync(attachment);

另请参阅

适用于

ReplaceAttachmentAsync(Uri, Attachment, RequestOptions, CancellationToken)

将附件替换为 Azure Cosmos DB 服务中的异步操作。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>> ReplaceAttachmentAsync (Uri attachmentUri, Microsoft.Azure.Documents.Attachment attachment, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceAttachmentAsync : Uri * Microsoft.Azure.Documents.Attachment * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Attachment>>
Public Function ReplaceAttachmentAsync (attachmentUri As Uri, attachment As Attachment, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Attachment))

参数

attachmentUri
Uri

要更新的附件的 URI。

attachment
Attachment

附件资源。

options
RequestOptions

(可选的) RequestOptions 请求的 。

cancellationToken
CancellationToken

(可选) A CancellationToken ,可供其他对象或线程用来接收取消通知。

返回

表示异步操作的服务响应的任务对象。

适用于