[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.]
Downloads the blob's contents to a file, using a conditional request based on the BlobRequestOptions that you specify. Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Downloads the blob's contents to a file, using a conditional request based on the BlobRequestOptions that you specify. Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)
Usage
Visual Basic |
---|
Dim instance As CloudBlob Dim fileName As String Dim options As BlobRequestOptions instance.DownloadToFile(fileName, options) |
Syntax
Visual Basic |
---|
Public Sub DownloadToFile ( _ fileName As String, _ options As BlobRequestOptions _ ) |
C# |
---|
public void DownloadToFile ( string fileName, BlobRequestOptions options ) |
C++ |
---|
public: void DownloadToFile ( String^ fileName, BlobRequestOptions^ options ) |
J# |
---|
JScript |
---|
Parameters
- fileName
Type: System.String
The path and file name of the target file.
- options
Type: Microsoft.WindowsAzure.StorageClient.BlobRequestOptions
An object that specifies any additional options for the request.
Example
The following code example downloads a blob to a local file only if the blob has been modified since January 1, 2012.
C# | Copy Code |
---|---|
static void DownloadBlobToFile(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)); // Return a reference to the blob. CloudBlob blob = blobClient.GetBlobReference("mycontainer/myblob"); // Download the blob to a local file only if it has been modified since a fixed date. DateTime dt = new DateTime(2012, 1, 1, 0, 0, 0, DateTimeKind.Utc); try { blob.DownloadToFile("c:\\temp\\mylocalblob.txt", new BlobRequestOptions() { AccessCondition = AccessCondition.IfModifiedSince(dt.ToUniversalTime()) }); } catch (StorageClientException e) { if (e.StatusCode == System.Net.HttpStatusCode.NotModified) Console.WriteLine("The blob was not modified since January 1, 2012."); else throw e; // some other StorageClientException, re-throw } } |
Remarks
This method downloads a blob to a file in the local file system. If the file does not exist, it is created; if it does exist, it is overwritten.
Warning |
---|
If you download a blob to an existing file and the size of the blob is less than that size of the file, the file will not be completely overwritten and data corruption may occur. This is a known bug in the client library. It's recommended that you delete the existing file on disk before downloading the blob. |
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.