Container.ReadItemStreamAsync(String, PartitionKey, ItemRequestOptions, CancellationToken) Container.ReadItemStreamAsync(String, PartitionKey, ItemRequestOptions, CancellationToken) Method

Definition

Reads a item from the Azure Cosmos service as an asynchronous operation.

public abstract System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage> ReadItemStreamAsync (string id, Microsoft.Azure.Cosmos.PartitionKey partitionKey, Microsoft.Azure.Cosmos.ItemRequestOptions requestOptions = null, System.Threading.CancellationToken cancellationToken = null);
abstract member ReadItemStreamAsync : string * Microsoft.Azure.Cosmos.PartitionKey * Microsoft.Azure.Cosmos.ItemRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Cosmos.ResponseMessage>

Parameters

id
String String

The cosmos item id

partitionKey
PartitionKey PartitionKey

The partition key for the item. PartitionKey

requestOptions
ItemRequestOptions ItemRequestOptions

(Optional) The options for the item request ItemRequestOptions

cancellationToken
CancellationToken CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

A Task containing a ResponseMessage which wraps a Stream containing the read resource record.

Examples

Read a response as a stream.


using(CosmosResponseMessage response = this.container.ReadItemStreamAsync("id", new PartitionKey("partitionKey")))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
        return;
    }
    
    using(Stream stream = response.ReadBodyAsync())
    {
        //Read or do other operations with the stream
        using (StreamReader streamReader = new StreamReader(stream))
        {
            string content =  streamReader.ReadToEndAsync();
        }
    }
}

Read a response as a stream.


using(ResponseMessage response = await this.container.ReadItemStreamAsync("id", new PartitionKey("partitionKey")))
{
    if (!response.IsSuccessStatusCode)
    {
        //Handle and log exception
        return;
    }
    
    using(Stream stream = response.ReadBodyAsync())
    {
        //Read or do other operations with the stream
        using (StreamReader streamReader = new StreamReader(stream))
        {
            string content =  streamReader.ReadToEndAsync();
        }
    }
}

Applies to