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

DocumentClient.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>>
override this.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>>
override this.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

请求的请求选项。

cancellationToken
CancellationToken

(表示请求取消的可选) CancellationToken

返回

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

实现

适用于