Create a blob storage container programmatically

前端 未结 2 985
清酒与你
清酒与你 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 13:02

        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);
    
                //Create a new container, if it does not exist
               container.CreateIfNotExists();
            } 
    

    Follow the guidline for container names:

    • A container name must be a valid DNS name, conforming to the
      following naming rules: Container names must start with a letter or
      number, and can contain only letters, numbers, and the dash (-)
      character.
    • Every dash (-) character must be immediately preceded and followed by a letter or number; consecutive dashes are not permitted in container names.

    • All letters in a container name must be lowercase.

    • Container names must be from 3 through 63 characters long.

提交回复
热议问题