2

I am trying to create a blob container with a name based on a value (AssetID) passed into the function as a parameter.

    public CloudBlobContainer GetCloudBlobContainer(int id)
    {

        // Retrieve storage account from connection-string
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString);

        // Create the blob client 
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Retrieve a reference to a container 
        CloudBlobContainer blobContainer = blobClient.GetContainerReference("AssetDocs" + id);

        try
        {

            // Create the container if it doesn't already exist
            if (blobContainer.CreateIfNotExist())
            {

                blobContainer.SetPermissions(
                   new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }
                );
            }
        }
        catch (WebException e)
        {
            return blobContainer;
        }

        return blobContainer;
    }

When I run the code I get the following exception:

An exception of type 'Microsoft.WindowsAzure.StorageClient.StorageClientException' occurred in Microsoft.WindowsAzure.StorageClient.dll but was not handled in user code

Additional information: One of the request inputs is out of range.

I tried to add a try...catch however this does not seem to trap the exception so I can find more details.

If tried adding id.ToString() and also removing id altogether but that didn't work either.

What am I doing wrong?

1 Answer 1

3

Cracked it! the container name must be in lower case.

 // Retrieve a reference to a container 
        CloudBlobContainer blobContainer = blobClient.GetContainerReference("assetdocs" + id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.