AccessCondition.IfNotModifiedSince Method

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Returns an access condition such that an operation will be performed only if the resource has not been modified since the specified time.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

Usage

Visual Basic
Dim lastModifiedUtc As DateTime
Dim returnValue As AccessCondition

returnValue = AccessCondition.IfNotModifiedSince(lastModifiedUtc)

Syntax

Visual Basic
Public Shared Function IfNotModifiedSince ( _
	lastModifiedUtc As DateTime _
) As AccessCondition
C#
public static AccessCondition IfNotModifiedSince (
	DateTime lastModifiedUtc
)
C++
public:
static AccessCondition IfNotModifiedSince (
	DateTime lastModifiedUtc
)
J#
JScript

Parameters

lastModifiedUtc

The last-modified time for the resource, expressed as a UTC value.

Return Value

A structure specifying the If-Unmodified-Since condition.

Example

The following code example checks an access condition on the source blob and copies the blob if the condition is met.

 Copy Code
static void CopyIfNotModifiedSince(Uri blobEndpoint, string accountName, string accountKey)
{
    //Create service client for credentialed access to the Blob service.
    CloudBlobClient blobClient = new CloudBlobClient(blobEndpoint, new StorageCredentialsAccountAndKey(accountName, accountKey));

    //Get a reference to the source blob.
    CloudBlob sourceBlob = blobClient.GetBlobReference("mycontainer/myblob.txt");
    sourceBlob.FetchAttributes();

    //Get a reference to the destination blob.
    CloudBlob destBlob = blobClient.GetBlobReference("mycontainer/copy-if-not-modified-since.txt");
    BlobRequestOptions options = new BlobRequestOptions();
    DateTime dt = new DateTime(2010, 9, 1, 0, 0, 0, DateTimeKind.Utc);

    try
    {
        //Copy the source blob to the destination blob if the source blob has not been modified since 9/1/2010.
        options.CopySourceAccessCondition = AccessCondition.IfNotModifiedSince(dt.ToUniversalTime());
        destBlob.CopyFromBlob(sourceBlob, options);
    }
    catch (StorageClientException e)
    {
        if (e.StatusCode == HttpStatusCode.PreconditionFailed)
        {
            Console.WriteLine("Access condition not met - blob " + sourceBlob.Uri + " has been modified since " + dt.ToUniversalTime());
        }
        else
        {
            Console.WriteLine("Error code: " + e.ErrorCode);
        }
    }
}

Remarks

Setting this access condition modifies the request to include the HTTP If-Unmodified-Since conditional header.

If this access condition is set, the operation is performed only if the resource has not been modified since the specified time.

See Specifying Conditional Headers for Blob Service Operations for more information.


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also