Esempio n. 1
0
        protected string GetAttachmentString(AttachmentReference attachmentReference)
        {
            var attachment = UnitOfWork.DocumentSession.Advanced.DatabaseCommands.GetAttachment(attachmentReference.AttachmentId);
            if (attachment != null && attachment.Data != null)
            {
                using(var streamReader = new StreamReader(attachment.Data(), Encoding.UTF8))
                {
                    return streamReader.ReadToEnd();
                }
            }

            return string.Empty;
        }
Esempio n. 2
0
        protected string GetAttachmentString(AttachmentReference attachmentReference, bool useBase64 = false)
        {
            var attachment = UnitOfWork.DocumentSession.Advanced.DocumentStore.DatabaseCommands.GetAttachment(attachmentReference.AttachmentId);
            if (attachment != null && attachment.Data != null)
            {
                if (useBase64)
                {
                    using (var ms = new MemoryStream())
                    {
                        var stream = attachment.Data();
                        stream.CopyTo(ms);
                        return Convert.ToBase64String(ms.ToArray());
                    }
                }

                using (var streamReader = new StreamReader(attachment.Data(), Encoding.UTF8))
                {
                    return streamReader.ReadToEnd();
                }
            }

            return string.Empty;
        }