【发布时间】:2013-07-30 19:59:58
【问题描述】:
我正在将注册条目记录到 CSV 文件中(因为稍后需要它来包含整个月的所有注册),方法是将条目附加到该文件的最后一行,例如:
using (StreamWriter w = new StreamWriter(currentPath, true))
{
w.WriteLine(fileRow);
}
但在 Windows Azure 中,我无法访问物理文件,因此我需要使用 Blob 存储。
如何对 Blob 块执行相同的操作?
我试过了:
CloudBlobContainer blobContainer = blobStorage.GetContainerReference(containerName);
cloudBlob = blobContainer.GetBlobReferenceFromServer(blobNameLogs);
MemoryStream oldText = new MemoryStream();
cloudBlob.DownloadToStream(oldText);
// record to save
string fileRow = row.ToFileRow();
// append
MemoryStream newText = new MemoryStream();
using (StreamWriter w = new StreamWriter(newText, System.Text.Encoding.Default))
{
w.WriteLine(oldText);
w.WriteLine(fileRow);
// set blob data
cloudBlob.UploadFromStream(newText);
}
但是在此操作之后我一直在文件上收到0 bytes ...我错过了什么?将文本附加到现有文件是否有更简单的操作?
【问题讨论】:
标签: c# azure-storage azure-blob-storage