Aliendreamer

downloadStreamFromServer

Sep 17th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1.    private async Task<MemoryStream> DownloadInvoiceFromFileServer(string invoiceInfoInvoiceId, string invoiceInfoFileExtension)
  2.         {
  3.             string path = AppSettingsConstants.FileServerEndPoint + $"/{invoiceInfoInvoiceId}.{invoiceInfoFileExtension}";
  4.             var memoryStream = new MemoryStream();
  5.             using (var fileStream = new FileStream(path, FileMode.Open))
  6.             {
  7.                 byte[] buffer = new byte[1024];
  8.                 int byteRead;
  9.                 while ((byteRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
  10.                 {
  11.                     await memoryStream.WriteAsync(buffer, 0, byteRead);
  12.                 }
  13.             }
  14.  
  15.             memoryStream.Position = 0;
  16.             return memoryStream;
  17.         }
Add Comment
Please, Sign In to add comment