c# - 如何在 C# 中创建 XML 文件并上传到 azure blob
问题描述
XDocument
我使用 C#库创建了 XML 数据。我尝试将 XML 数据上传到 azure blob。下面是我的代码。
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System.Xml.Linq;
public CloudBlobClient blobClient {get;}
public AzureBlobServices(string storageAccountConnection)
{
StorageAccountConnection = storageAccountConnection;
storageAccount = CloudStorageAccount.Parse(StorageAccountConnection);
blobClient = storageAccount.CreateCloudBlobClient();
}
public async Task sampleFile()
{
XDocument doc = new XDocument( new XElement( "body",
new XElement( "level1",
new XElement( "level2", "text" ),
new XElement( "level2", "other text" ) ) ) );
MemoryStream stream = new MemoryStream();
doc.Save(stream);
var container = blobClient.GetContainerReference("folder location");
CloudBlockBlob blockBlob = container.GetBlockBlobReference("Data/xml/Data.csv");
await blockBlob.UploadFromStreamAsync(stream);
}
但是文件已上传,但文件中没有任何内容。代码有什么问题?
解决方案
尝试重置流的位置:
MemoryStream stream = new MemoryStream();
doc.Save(stream);
stream.Position = 0;
推荐阅读
- python - 插值函数 - 矩阵
- android - 使用 Kotlin 向 ROOM 数据库中的特定 id 添加注释
- .net - WPF DataGrid 绑定类中的某些字段不是全部
- kubernetes - 使用入口资源中的主机名/子域从外部访问应用程序
- c# - AWS Textract .Net SDK 的其他选项
- python - 如何使用 Python 从 Windows 将文件放在经过密码验证的 SFTP 服务器上?
- android - 尝试插入 SQLite 时出现 -1 错误
- c# - 如果水晶报表中满足条件,则禁止链接
- javascript - LitElement:从属性设置样式
- java - Apache Camel 可以处理的最大路由数