CloudBlob.DownloadToFile Method (String)

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.]

Downloads the blob's contents to a file.

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

Usage

Visual Basic
Dim instance As CloudBlob
Dim fileName As String

instance.DownloadToFile(fileName)

Syntax

Visual Basic
Public Sub DownloadToFile ( _
	fileName As String _
)
C#
public void DownloadToFile (
	string fileName
)
C++
public:
void DownloadToFile (
	String^ fileName
)
J#
JScript

Parameters

fileName

Type: System.String

The path and file name of the target file.

Example

The following code example downloads a blob to a local file.

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.txt");

    // Download the blob to a local file.
    blob.DownloadToFile("c:\\mylocalblob.txt");
}

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.

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