title: Problem downloading a PDF file from Azure File to bytes using Azure.Storage.Files.Shares
body: <p>I previously used Windows.AzureStorage to download PDF files from my Azure storage account and stream the PDF to a browser.  Since it was deprecated, I am trying to get in line with Azure.Files.Storage.Shares.</p>
  <p>Note that I was able to use Windows.AzureStorage for years.</p>
  <p>I am able to get the file from Azure and read the bytes but when I try to stream them to the browser the file is not a valid PDF.</p>
  <p>The old way of doing it looked like this:</p>
  <pre><code>                    pdfFile.FetchAttributes()
  
                      Dim byteData As Byte() = New Byte(pdfFile.Properties.Length - 1) {}
  
                      pdfFile.DownloadToByteArray(byteData, 0)
  
                      byteReturnValue = byteData
  </code></pre>
  <p>This is a hard coded test function that &quot;works&quot; but does not render a valid PDF. The number of bytes returned using the new method shown below is 98,284.  The number of bytes returned in the previous (successful) method is 98,284.  Is it something to do with the &quot;Offset&quot;??</p>
  <p>I'm at my wits end.</p>
  <pre><code>    Public Shared Function GetPDFStream() As Byte()
  
      Dim connectionString As String = ConfigurationManager.AppSettings(&quot;StorageConnectionString&quot;)
      Dim shareName As String = &quot;root&quot;
      Dim dirName As String = &quot;invoicestest\MSEVN&quot;
      Dim fileName As String = &quot;EVE0042361.pdf&quot;
      Dim share As ShareClient = New ShareClient(connectionString, shareName)
      Dim directory As ShareDirectoryClient
      Dim cloudfile As ShareFileClient
      Dim download As ShareFileDownloadInfo
  
      directory = share.GetDirectoryClient(dirName)
  
      cloudfile = directory.GetFileClient(fileName)
  
      download = cloudfile.Download()
  
      Dim byteData As Byte() = New Byte(download.ContentLength - 1) {}
  
      download.Content.Read(byteData, 0, download.ContentLength - 1)
  
      GetPDFStream = byteData
  
  End Function
  </code></pre>
  <p>These bytes get returned to another page which outputs the bytes to the browser (this part is fine but I am showing how the bytes get used)</p>
  <pre><code>                    Response.Buffer = True
  
                      Dim strMimeType = &quot;application/pdf&quot;
  
                      Response.Clear()
                      Response.ContentType = strMimeType
  
                      Response.AddHeader(&quot;content-disposition&quot;, &quot;attachment;filename=&quot; &amp; strFileName)
  
                      Response.OutputStream.Write(byteReturnValue, 0, byteReturnValue.Length)
                      Response.OutputStream.Flush()
                      Response.OutputStream.Close()
                      Response.Flush()
                      Response.Close()
  </code></pre>
  <hr />