title: Get File.Stream using path
body: <p>I would like to get the File and pass it as stream but I'm not sure how to do this. I do have a path where the file is located. So basically using this path I'm going to retrieve this file and save it as stream. But correct me if I'm wrong, but is it correct to assume that &quot;Reading as Stream&quot; is something like it's actually opening the file and reading it?</p>
  <p>Are there anyway to just retrieve or Copy the file into a FileStream or MemoryStream? Right now I have this but not sure if this is correct</p>
  <pre><code> foreach (string filePath in filePaths)
   {
        string filename = Path.GetFileName(filePath);
        //Constants.Conventions.MediaTypes.Image
        string mediaType = Constants.Conventions.MediaTypes.File;
        string ext = Path.GetExtension(filename);
        IMedia media = Services.MediaService.CreateMedia(filename, Constants.System.Root, mediaType);
        MemoryStream ms = new MemoryStream();
        using (Stream stream = System.IO.File.OpenRead(filePath))
        {
             ms.WriteTo(stream);
        }
        media.SetValue(&quot;umbracoFile&quot;, filename, ms);
        // Save the media
        Services.MediaService.Save(media);
        media = null;
        System.IO.File.Delete(filePath);
   }
  </code></pre>
  <p>I'm not so sure if this is the best approach. But the main goal is to retrieve that file from the path and save it in <code>media.SetValue(&quot;umbracoFile&quot;, filename, ms);</code> as it's requiring a <code>Stream</code> as input. How do I do this in a most efficient way? I'm always getting outofmemoryexception due to large file. So I'm guessing because it's reading it as Stream that it's throwing an error on large file. So maybe we can just copy it to save. I'm not so sure really needs help here</p>
  <p>Update:
  Here is the config to make sure I don't run out of memory</p>
  <pre><code>&lt;httpRuntime requestValidationMode=&quot;2.0&quot; enableVersionHeader=&quot;false&quot; maxRequestLength=&quot;2097151&quot; executionTimeout=&quot;50000000&quot; targetFramework=&quot;4.5&quot; fcnMode=&quot;Single&quot; /&gt;
  
  &lt;location path=&quot;umbraco&quot;&gt;
    &lt;system.web&gt;
      &lt;httpRuntime maxRequestLength=&quot;204800&quot; executionTimeout=&quot;99999&quot;/&gt;
    &lt;/system.web&gt;
  &lt;/location&gt;
  
  &lt;security&gt;
    &lt;requestFiltering&gt;
      &lt;requestLimits maxAllowedContentLength=&quot;2294967295&quot; /&gt;
    &lt;/requestFiltering&gt;
  &lt;/security&gt;
  </code></pre>
  <p>And this is the build of my project</p>
  <p><a href="https://i.stack.imgur.com/l1vMe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1vMe.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/qwKWS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qwKWS.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/MC1rS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MC1rS.png" alt="enter image description here" /></a></p>