title: Handling file size for SQL FILESTREAM data
body: <p>What is the proper way to handle file sizes when using Sql Server's FILESTREAM feature to store documents in the database?</p>
  
  <p>I know that you can use the TSQL command <code>DATALENGTH()</code> on the filestream column, but regarding to <a href="http://technet.microsoft.com/en-us/library/dd206979%28v=sql.105%29.aspx" rel="nofollow">this Microsoft article</a> this might not always be the best idea:</p>
  
  <blockquote>
    <p>Avoid retrieving the data length of lots of BLOB files in an application. This is a time-consuming operation because the size is not stored in the SQL Server Database Engine. If you must determine the length of a BLOB file, use the Transact-SQL DATALENGTH() function to determine the size of the BLOB if it is closed. DATALENGTH() does not open the BLOB file to determine its size.</p>
  </blockquote>
  
  <p>I am a bit unclear if the above says that you should avoid DATALENGTH() if possible or if it is the recommended way to retrieve the file size.</p>
  
  <p><strong>If I have to access document sizes often to show it to the user as metadata, what is the recommended way to retrieve them?</strong> Store them in a separate field? Or is datalength() fast enough?</p>