0

I am porting some old application services code into Microsoft Azure and need a little help.

I am pulling in some data from a stored procedure and creating a SpreadsheetLight document (this was brought in from the old code since my users want to keep the extensive formatting that was already built into this process). That code works fine, but I need to write the file directly into our azure blob container without saving a local copy first (as this process will run in a pipeline). Using some sample code I found as a guide, I was able to get it working in debug by saving locally and then uploading that out to the blob storage... but now I need to find a way to remove that local save prior to the upload.

Craig_Th
  • 1
  • 2
  • I found this person asking the same question a few months back, but the only answer was the solution that I have gotten working... hoping there is a better way. (NOTE: I would've added a comment on the post, but I don't have the reputation points to be able to do that yet). https://stackoverflow.com/questions/65692431/save-created-excel-file-to-azure-blob-container-path-issue – Craig_Th Sep 14 '21 at 19:51

1 Answers1

0

Well I actually stumbled on the solution.

string connectionString = "YourConnectionString";
string containerName = "YourContainerName";
string strFileNameXLS = "YourOutputFile.xlsx";

BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
BlobClient blobClient = blobContainerClient.GetBlobClient(strFileNameXLS);

SLDocument doc = YourSLDocument();

using (MemoryStream ms = new MemoryStream())
{
    doc.SaveAs(ms);
    ms.Position = 0;
    await blobClient.UploadAsync(ms, true);
    ms.Close();
}
bad_coder
  • 11,289
  • 20
  • 44
  • 72
Craig_Th
  • 1
  • 2