我在这里使用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);我可以很好地下载文件,但是它们已经损坏了……我是不是漏掉了什么?
发布于 2010-08-06 15:54:04
您可以直接使用FileContentResult -这样您就不必通过MemoryStream。这样一来,你就不会有太大的风险去破坏任何东西。
return FileContent(fileAttachment.Content, attachment.ContentType);如果不希望文件在浏览器中以内联方式显示,则可能还需要设置FileDownloadName。
https://stackoverflow.com/questions/3421250
复制相似问题