通过 FileStreamResult 获取 EmailMessage 附件
我在这里有这段代码,我使用 EWS 从 Exchange Server 上的电子邮件消息中检索附件
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);
我可以很好地下载该文件,但是它们已损坏...我缺少什么吗?
I have this code here where I retrieve an attachment from an Email Message that is on the Exchange Server using 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);
I can download the file just fine however they are corrupted... Is there something I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以直接使用 FileContentResult相反 - 这样您就不必通过
MemoryStream
。这样,您破坏任何东西的风险就会降低。如果您不希望文件在浏览器中内联显示,您可能还需要设置
FileDownloadName
。You can use a FileContentResult directly instead - that way you don't have to go via a
MemoryStream
. That way, you have less risk of breaking anything.You might also want to set the
FileDownloadName
if you don't want the file to display inline within the browser.