title: How do I get the filesize from the Microsoft.SharePoint.Client.File object?
body: <p>I'm looking for a good way to get filesize from the <code>Microsoft.SharePoint.Client.File</code> object.</p>
  
  <p>The <code>Client</code> object does not have a <code>Length</code> member.</p>
  
  <p>I tried this:</p>
  
  <pre><code>foreach (SP.File file in files)
  {
      string path = file.Path;
      path = path.Substring(this.getTeamSiteUrl().Length);
      FileInformation fileInformation = SP.File.OpenBinaryDirect(this.Context, path);
      using (MemoryStream memoryStream = new MemoryStream())
      {
          CopyStream(fileInformation.Stream, memoryStream);
          file.Size = memoryStream.Length;
      }
  }
  </code></pre>
  
  <p>Which gave me a length through using the <code>MemoryStream</code>, but it's not good for performance.  This file also does not belong to a document library. Since it's an attached file, I can't convert it to a <code>ListItem</code> object using <code>ListItemAllFields</code>.  If I could convert it to a <code>ListItem</code>, I could get its size using: <code>ListItem["File_x0020_Size"]</code></p>
  
  <p>How do I get the filesize of the <code>Client</code> object in SharePoint using C#?</p>