Question

I have a web app that I need to change to work with Windows Azure Web Sites. Two text file are uploaded and parsed then a third file is written line by line with the parsed data. I've found that I can't upload files directly to an Azure Web Site and need to use Blob Storage. This is pretty straight forward. What I am unable to find is how to write a text file line by line to a Blob or maybe there would be a better solution? I need to re-create this code to work with an Azure Web Site:

using (var writer = new StreamWriter(filePath, false))
        {
           foreach (Product product in pm.GetAll())
            {
                    fp = pm.MakeFinal(product);

                    curLine.Append(fp.InventoryNumber + "\t");
                    curLine.Append(fp.SellerCost + "\t");
                    curLine.Append(fp.RetailPrice + "\t");
                    curLine.Append(fp.StartingBid + "\t");
                    curLine.Append(fp.BINPrice + "\t");
                    curLine.Append(fp.CAPrice + "\t");
                    curLine.Append(fp.Weight + "\t");
                    curLine.Append(fp.Length + "\t");
                    curLine.Append(fp.Width + "\t");
                    curLine.Append(fp.Height + "\t");
                    curLine.Append(fp.Brand + "\t");
                    curLine.Append(fp.Manufacturer + "\t");
                    curLine.Append(fp.MPN + "\t");
                    curLine.Append(fp.Quantity);

                    writer.WriteLine(curLine.ToString());
            }
        }

Is it possible to use a streamwriter to write a text file line by line to an Azure Blob. If not, what would be a good alternative way to do this?

Edit ------------------------------

This doesn't answer the question I asked but I no longer need to use Azure blob storage. I added the following to my web.config and both files upload fine, the third file is being created fine also:

<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="2000000000" />
  </requestFiltering>
</security>
Was it helpful?

Solution

You have local disk access, where you can construct your new file exactly how you're doing it now. Once you finish constructing the file, you can just copy the file to a blob (which is supported via the blob REST API, and wrapped by the .NET SDK and other language SDKs). Just look at the CloudBlockBlob class and the methods UploadFromFileand UploadFromFileAsync(there are also methods to upload from stream).

There's also a CloudBlobStream class that supports reading and writing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top