Azure: Why is my blob 0KB when I move it?

I was archiving documents in Blob Storage and found that the target files were always being rendered as 0 KB.

I was using the following code:

var storageAccount = CloudStorageAccount.Parse("CONNECTIONSTRING");
var blobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference("container");
var blob = blobContainer.GetBlobReference("myfilename")

// Get the source as a stream
Stream stream = new MemoryStream();
blob.DownloadToStream(stream);

var destBlob = blobContainer.GetBlockBlobReference(blob.Name);
destBlob.UploadFromStream(stream);

blob.Delete();

The code should work, except for the fact that the stream needs to be repointed to the start for the download to work.

blob.DownloadToStream(stream); (from above)
stream.Position = 0;

And now the copy/move works

Comments

Popular posts from this blog

SharePoint 2013: Error updating managed account credentials

Error deploying Nintex workflow: An item with the same key has already been added