Pergunta

Eu tenho esse código aqui, onde recupero um anexo de uma mensagem de e -mail que está no servidor Exchange usando EWS

            Attachment attachment = message.Attachments.Single(att => att.ContentId == Request.QueryString["cid"]);
            attachment.Load();
            FileAttachment fileAttachment = attachment as FileAttachment;


            fileAttachment.Load();
            byte[] bytes = fileAttachment.Content;
            Stream theMemStream = new MemoryStream();

            theMemStream.Write(bytes, 0, bytes.Length);

            return new FileStreamResult( theMemStream, attachment.ContentType);

Eu posso baixar o arquivo muito bem, no entanto, eles estão corrompidos ... há algo que estou perdendo?

Foi útil?

Solução

Você pode usar um FileContentResult diretamente em vez disso - dessa maneira você não precisa ir através de um MemoryStream. Dessa forma, você tem menos risco de quebrar qualquer coisa.

return FileContent(fileAttachment.Content, attachment.ContentType);

Você também pode querer definir o FileDownloadName se vocês não deseja que o arquivo seja exibido embutido no navegador.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top