I have a text file uploaded in my Azure storage account.Now, in my worker role , what i need to do is every time it is run, it fetches some content from Database, and that content must be written in the Uploaded text file, specifically , each time the content of Text file should be overwritten with some new content.
Here, they have given a way to upload a text file to your storage and also delete a file.But i don't want to do that, need to just MODIFY the already present text file each time.
I'm assuming you're referring to storing a file in a Windows Azure blob. If that's the case: A blob isn't a file system; it's just a place to store data (and the notion of a file is a bit artificial - it's just... a blob stored in a bunch of blocks).
To modify the file, you would need to download it and save it to local disk, modify it (again, on local disk), then do an upload. A few thoughts on this:
Just to make sure this download/modify/upload pattern is clear, here's a very simple example (I just typed this up quickly in Visual Studio but haven't tested it. Just trying to illustrate the point):
// initial setup
var acct = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
var client = acct.CreateCloudBlobClient();
// what you'd call each time you need to update a file stored in a blob
var blob = client.GetContainerReference("mycontainer").GetBlockBlobReference("myfile.txt");
using (var fileStream = System.IO.File.OpenWrite(@"path\myfile.txt"))
{
blob.DownloadToStream(fileStream);
}
// ... modify file...
// upload modified file
using (var fileStream = System.IO.File.OpenWrite(@"path\myfile.txt"))
{
blob.UploadFromStream(fileStream);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With