1

How to create an empty text file ( or text with some message )inside my blob container

var destBlob = blobClient.GetBlobReference(myblob);

something like https://myxyzstorage.blob.core.windows.net/mycontainer/newfolder/newTextfile.txt

Millar
  • 1,095
  • 6
  • 16
  • 34

3 Answers3

5

If you are using a newer version of Windows Azure Storage Client Library, you should create a container and then use it to get a blob reference with the path you’d like your blob to have within the container. To create a path similar to the one you posted:

CloudBlobContainer container = blobClient.GetContainerReference(“mycontainer”);
container.CreateIfNotExists();

CloudBlockBlob blob = container.GetBlockBlobReference("newfolder/newTextfile.txt");
blob.UploadText("any_content_you_want");
Emily Gerner
  • 2,427
  • 16
  • 16
1

If you are using .NET standard, this code should work.

CloudBlockBlob blob = blobContainer.GetBlockBlobReference("File Name");

blob.UploadTextAsync("<<File Content here>>");
Sebastian D'Agostino
  • 1,575
  • 2
  • 27
  • 44
0

The following example from here helped me to solve this

public Uri UploadBlob(string path, string fileName, string content)
{
    var cloudBlobContainer = cloudBlobClient.GetContainerReference(path);
    cloudBlobContainer.CreateIfNotExist();

    var blob = cloudBlobContainer.GetBlobReference(fileName);
    blob.UploadText(content);

    return blob.Uri;
}
Millar
  • 1,095
  • 6
  • 16
  • 34
  • Only comment I would have is to always have a retry policy in Production. The storage client library includes this capability and can make weird/intermittent errors go away (espcially in a high volume prod enviornment): http://blogs.msdn.com/b/windowsazurestorage/archive/2011/02/03/overview-of-retry-policies-in-the-windows-azure-storage-client-library.aspx – Bart Czernicki Oct 05 '13 at 00:10