title: Can I get file.OpenStreamForReadAsync() from file.OpenStreamForWriteAsync()?
body: <p>I am still learning the tricks of read/write file streams and hope someone could help if what I am looking for is feasible.</p>
  
  <p>The code below makes WebApi calls (note <code>GetAsync()</code> on line 2) to get an image file Id and save downloaded file to database with computed Md5Hash. The code works fine, but in the interest of efficiency I was wondering if it's possible to get <code>file.OpenStreamForReadAsync()</code> from <code>file.OpenStreamForWriteAsync()</code> (not sure even if this is possible, but I can see some extension methods that operate on a stream but no luck with attempts I've made so far). If this is possible, I can avoid saving a file and opening it again, by instead making the GetMD5Hash() method call within the <code>using (var fileStream = await file.OpenStreamForWriteAsync()){ ... }</code> block.</p>
  
  <p>Can I have the equivalent of <code>Utils.GetMD5Hash(stream);</code>, shown below outside the <code>using</code> block, inside the block, the intention being to avoid opening the file outside of the <code>using</code> block?</p>
  
  <pre><code>var client = new HttpClient();
  var response = await client.GetAsync(new Uri($"{url}{imageId}")); // call to WebApi; url and imageId defined earlier
  
  if (response.IsSuccessStatusCode)
  {
      using (var contentStream = await response.Content.ReadAsInputStreamAsync())
      {
          var stream = contentStream.AsStreamForRead();
          var file = await imagesFolder.CreateFileAsync(imageFileName, CreationCollisionOption.ReplaceExisting);
          using (var fileStream = await file.OpenStreamForWriteAsync())
          {
              await stream.CopyToAsync(fileStream, 4096);
  
              // &gt;&gt;&gt;&gt; At this point, from the Write fileStream, can I get the equivalent of file.OpenStreamForReadAsync() ??
  
          }
  
          var stream = await file.OpenStreamForReadAsync();
          string md5Hash = await Utils.GetMD5Hash(stream);
          await AddImageToDataBase(file, md5Hash);
      }
  }
  </code></pre>