【问题标题】:How to create a XML file in azure storage?如何在 Azure 存储中创建 XML 文件?
【发布时间】:2017-03-07 17:08:38
【问题描述】:

我是 Azure 存储的新手。我想在其中创建一个容器和一个 blob(XML 文件或其他文件)。这是创建容器的代码,但我在如何创建 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();

任何人都可以提供一些代码示例会很棒!

非常感谢!

【问题讨论】:

    标签: c# asp.net-mvc azure-blob-storage


    【解决方案1】:

    完成上述代码以获取容器的引用后,请执行以下操作:

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

    【讨论】:

    • 你还需要创建像 blob.CreateIfNotExists(); 这样的 xml 吗?
    • 并非如此。我使用上面的代码在 MVC 中从我的控制器创建新的 HTML 文件。我不知道这样的 blob.CreateIfNotExists()
    猜你喜欢
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 2012-01-25
    • 2015-09-11
    • 2018-01-22
    • 2021-04-30
    相关资源
    最近更新 更多