I'm trying to download all Blobs from a single Azure container using code. When I download each Blob I want the new file names to be consecutive numbers from 2.jpg upwards through 3.jpg, 4.jpg 5.jpg etc. This is not the name of the Blobs in the azure container, I dont know the name of each Blob when the code runs.
I seem to be falling at the last hurdle, I cant figure out what to put into my foreach
block to get the files into the \home\pi\Pictures\
directory on my local hard drive.
urls.DownloadToStream(FileStream);
is throwing an error that
List String does not contain a definition for DownloadToStream
and
FileStream is a type which is not valid in the given context.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Configuration;
using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
namespace CPGetAdverts
{
class Program
{
static void Main(string[] args)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureImagesConnection"].ConnectionString);
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
var container = blobClient.GetContainerReference("xxxxxx/").ListBlobs();
// Retrieve filenames from container List
var urls = new List<string>();
int fileName = 2;
foreach (var blob in container)
{
using (var fileStream = System.IO.File.OpenWrite(@"\home\pi\Pictures\"+ fileName + ".jpg")) ;
urls.DownloadToStream(FileStream);
fileName++;
}
}
}
}
Any help is very much appreciated.