SalimAzureBlobAPI/SalimAzureAPI/AzureBlobManager.cs
/// <summary>
/// Recursive function to upload files in a directory to an Azure blob directory. 
/// HASN'T BEEN FULLY TESTED.
/// </summary>
/// <param name="sourceDirectory">The directory containing all the files to be copied</param>
/// <param name="containerName">The target Azure container</param>
/// <param name="prefixAzureFolderName">The destination "folder" to copy everything to in Azure.</param>
/// <returns>true indicating success; false otherwise.</returns>
Recursive function to upload files in a directory to an Azure blob directory.
HASN'T BEEN FULLY TESTED.
Recursive function to upload files in a directory to an Azure blob directory . HASN ' T BEEN FULLY TESTED .
private bool UploadDirectory(string sourceDirectory, string containerName, string prefixAzureFolderName)
        {
            return ExecuteWithExceptionHandlingAndReturnValue(
                () =>
                {
                    if (!DoesContainerExist(containerName))
                    {
                        CreateContainer(containerName);
                    }
                    var folder = new DirectoryInfo(sourceDirectory);
                    FileInfo[] files = folder.GetFiles();
                    string blobName = String.Empty;
                    foreach (var fileInfo in files)
                    {
                        blobName = fileInfo.Name;
                        if (!string.IsNullOrEmpty(prefixAzureFolderName))
                        {
                            blobName = prefixAzureFolderName + "/" + blobName;
                        }
                        PutBlob(containerName, blobName, File.ReadAllBytes(fileInfo.FullName));
                    }
                    DirectoryInfo[] subFolders = folder.GetDirectories();
                    string prefix = String.Empty;
                    foreach (var directoryInfo in subFolders)
                    {
                        prefix = directoryInfo.Name;
                        if (!string.IsNullOrEmpty(prefixAzureFolderName))
                        {
                            prefix = prefixAzureFolderName + "/" + prefix;
                        }
                        UploadDirectory(directoryInfo.FullName, containerName, prefix);
                    }
                });
        }
private bool UploadDirectory ( string sourceDirectory , string containerName , string prefixAzureFolderName ) { return ExecuteWithExceptionHandlingAndReturnValue ( ( ) => { if ( ! DoesContainerExist ( containerName ) ) { CreateContainer ( containerName ) ; } var folder = new DirectoryInfo ( sourceDirectory ) ; FileInfo [ ] files = folder . GetFiles ( ) ; string blobName = String . Empty ; foreach ( var fileInfo in files ) { blobName = fileInfo . Name ; if ( ! string . IsNullOrEmpty ( prefixAzureFolderName ) ) { blobName = prefixAzureFolderName + " " + blobName ; } PutBlob ( containerName , blobName , File . ReadAllBytes ( fileInfo . FullName ) ) ; } DirectoryInfo [ ] subFolders = folder . GetDirectories ( ) ; string prefix = String . Empty ; foreach ( var directoryInfo in subFolders ) { prefix = directoryInfo . Name ; if ( ! string . IsNullOrEmpty ( prefixAzureFolderName ) ) { prefix = prefixAzureFolderName + " " + prefix ; } UploadDirectory ( directoryInfo . FullName , containerName , prefix ) ; } } ) ; }
Recursive function to upload files in a directory to an Azure blob directory.
Recursive function to upload files in a directory to an Azure blob directory .
true indicating success; false otherwise.
true indicating success ; false otherwise .
sourceDirectory
string
The directory containing all the files to be copied
The directory containing all the files to be copied
containerName
string
The target Azure container
The target Azure container
prefixAzureFolderName
string
The destination "folder" to copy everything to in Azure.
The destination " folder " to copy everything to in Azure .