Create a blob storage container programmatically

前端 未结 2 984
清酒与你
清酒与你 2021-02-13 12:46

I have a requirement whereby on creation of a company an associated blob storage container is created in my storageaccount with the container name set to the string variable pas

2条回答
  •  情深已故
    2021-02-13 12:59

    CloudBlobContainer container = new CloudBlobContainer("https://mystore.blob.core.windows.net/" + subDomain);
    

    This just creates an instance of CloudBlobContainer object. To create a container in your storage account, you would need to call CreateIfNotExists or Create function on this object.

    Try this code instead:

    public void AddCompanyStorage(string subDomain)
        {
            //get the storage account.
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                System.Configuration.ConfigurationManager.AppSettings["StorageConnectionString"].ToString());
    
            //blob client now
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();            
    
            //the container for this is companystyles
            CloudBlobContainer container = blobClient.GetContainerReference(subDomain);
            container.CreateIfNotExists();
    
        }
    

提交回复
热议问题