2016-10-25 7 views
0

Ich bin neu in Azure-Speicher.Ich möchte einen Container und auch ein Blob (XML-Datei oder was auch immer) darin erstellen. Hier ist der Code zum Erstellen eines Containers, aber ich habe Probleme beim Erstellen von XML (nicht Formular lokal hochladen).Wie erstelle ich eine XML-Datei im Azure-Speicher?

// 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(); 

Jeder kann einige Codebeispiel wäre großartig!

Vielen Dank!

Antwort

0

Sobald Sie mit dem obigen Code getan werden anhand eines Containers zu erhalten, gehen Sie wie folgt:

//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

Vielen Dank guter Herr! –

+0

Auch müssen Sie die XML so etwas wie blob.CreateIfNotExists() erstellen; –

+0

nicht wirklich. Ich verwende den obigen Code, um neue HTML-Dateien von meinem Controller in MVC zu erstellen. Ich bin nicht bewusst, wie blob.CreateIfNotExists() – JOW

Verwandte Themen