Uploading a file to azure blob storage

string finalUrl = "";


try {


// Connect to the storage account's blob endpoint


CloudStorageAccount account = CloudStorageAccount.Parse(conn);


CloudBlobClient client = account.CreateCloudBlobClient();


//create a container


string blobContainer = "containerfolder" ; // your container folder name


CloudBlobContainer cloudBlobContainer = client.GetContainerReference(blobContainer);


//create a container if it is not already exists


if (cloudBlobContainer.CreateIfNotExists())


{


cloudBlobContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); }


// Create the blob in the container


CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference( fileName);


// Upload the zip and store it in the blob


// Create or overwrite the "myblob" blob with contents from a local file.


using (var fileStream = System.IO.File.OpenRead(filePath + fileName))


{


blob.UploadFromStream(fileStream);


finalUrl = blob.Uri.ToString();


}


}


catch (Exception ex)


{


MessageBox.Show(ex.Message);


}


return finalUrl;