title: C#: How to generate StreamContent only for first line of file
body: <p>I have files with the first line as a header,</p>
  
  <p><a href="https://i.stack.imgur.com/pCRHz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pCRHz.png" alt="enter image description here"></a></p>
  
  <p>Now, I have a Web API Controller code which accepts only <code>StreamContent</code>,</p>
  
  <pre><code>using (FileStream fs = new FileStream(@"C:\Files\test_Copy.txt", FileMode.CreateNew, FileAccess.Write))
              {
                  await result.Content.CopyToAsync(fs);
              }
  </code></pre>
  
  <p>From client application, I am converting <code>fileStream</code> to <code>StreamContent</code> and post to Web API call.</p>
  
  <pre><code>Content = new StreamContent(fileStream),
  </code></pre>
  
  <p>I am able to send entire file content using the below code. Question: Can I send only the first line of the file as <code>StreamContent</code>?</p>
  
  <p>Here I am using both client and server code in a console application,</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Get().Wait();
      }
  
  
      public static async Task&lt;HttpResponseMessage&gt; Get()
      {
          using (var fileStream = new FileStream(@"C:\Files\test.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
          {
              var result = new HttpResponseMessage(HttpStatusCode.OK)
              {
                  //how to send only first line of file as a "Content"
                  Content = new StreamContent(fileStream),
              };
  
              using (FileStream fs = new FileStream(@"C:\Files\test_Copy.txt", FileMode.CreateNew, FileAccess.Write))
              {
                  await result.Content.CopyToAsync(fs);
              }
  
              return result;
          }
  
      }
  }
  </code></pre>