/// <summary>
        /// Downloads the attachment as a stream.
        /// </summary>
        /// <param name="containerTitle">The container title.</param>
        /// <param name="entityId">The entity id.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public virtual Stream DownloadAttachment(string containerTitle, Guid entityId, string fileName)
        {
            var result = new MemoryStream();

            SPSite site;
            var    web = GetDocumentStoreWeb(out site);

            SPList   list;
            SPFolder folder;

            if (SPDocumentStoreHelper.TryGetFolderFromPath(web, containerTitle, out list, out folder, String.Empty) == false)
            {
                return(null);
            }

            SPFile attachment;

            if (SPDocumentStoreHelper.TryGetDocumentStoreAttachment(list, folder, entityId, fileName, out attachment) == false)
            {
                return(null);
            }

            var attachmentStream = attachment.OpenBinaryStream();

            DocumentStoreHelper.CopyStream(attachmentStream, result);

            result.Seek(0, SeekOrigin.Begin);
            return(result);
        }
        private static void CreateOrUpdateCachedFile(SPFile spFile, SPDirectory directory)
        {
            using (var spFileStream = spFile.OpenBinaryStream())
            {
                using (var outputStream = directory.CreateCachedOutputAsStream(spFile.Name))
                {
                    DocumentStoreHelper.CopyStream(spFileStream, outputStream);
                    outputStream.Flush();
                }
            }

            directory.WriteCachedFileETag(spFile.Name, spFile.ETag);
        }