2016-10-25 66 views
0

我是新來的Azure存儲。我想創建一個容器,也是一個blob(XML文件或其他)。這裏是創建一個容器的代碼,但我很難創建XML(不上傳本地表單)。如何在Azure存儲中創建XML文件?

// Retrieve storage account from connection string. 
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
      CloudConfigurationManager.GetSetting("StorageConnectionString")); 

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

     // Retrieve a reference to a container. 
     CloudBlobContainer container = blobClient.GetContainerReference("XXXXXXXX"); 

     // Create the container if it doesn't already exist. 
     container.CreateIfNotExists(); 

任何人都可以提供一些代碼示例將是偉大的!

非常感謝!

回答

0

一旦你與上面的代碼來獲得一個集裝箱的參考要做,就做到如下:

//Create reference to a Blob that May or Maynot exist under the container 
CloudBlockBlob blockBlob = container.GetBlockBlobReference("something.xml"); 
// Create or overwrite the "something.xml" blob with contents from a string 

      string s = "your XML"; 
      await blockBlob.UploadTextAsync(s); 
+1

非常感謝你的好先生! –

+0

另外,你是否需要創建xml,如blob.CreateIfNotExists();? –

+0

不是真的。我使用上面的代碼在MVC中從我的控制器創建新的HTML文件。我不知道這樣的blob.CreateIfNotExists() – JOW

相關問題