Public · Protected · Private
Uploading a file to azure blob storage
Type: Public  |  Created: 2019-10-04  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • 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;

This blog is frozen. No new comments or edits allowed.