[英]Open new formats Microsoft Office without Office Online (web apps) in ASP NET MVC
I have problem with open new format documents Microsoft Office (docx, xlsx etc). 我在打开新格式的文档Microsoft Office(docx,xlsx等)时遇到问题。 I develop my project using ASP NET MVC.
我使用ASP NET MVC开发项目。
I wrote new method: 我写了新方法:
[HttpGet]
[AllowAnonymous]
public ActionResult DownloadFileNew(Guid Id)
{
FileTable fileTable = _DocumentService.GetFile(Id);
HttpResponseBase response = ControllerContext.HttpContext.Response;
response.ContentType = fileTable.ContentType;
response.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", fileTable.FileName));
MemoryStream ms = new MemoryStream(fileTable.Data);
FileStreamResult document = new FileStreamResult(ms, fileTable.ContentType);
document.FileStream.Seek(0, SeekOrigin.Begin);
document.FileStream.CopyTo(response.OutputStream, (int)document.FileStream.Length);
response.Flush();
return new EmptyResult();
}
But don't work with new formats, only old format (doc, xls etc). 但不要使用新格式,而只能使用旧格式(doc,xls等)。
When I try open document I take error message: "Excel web app cannot open this document ..." 当我尝试打开文档时,出现错误消息:“ Excel Web应用程序无法打开此文档...”
Log file: 日志文件:
Not sure what the ContentType you are using, but it has to be 不确定您使用的是什么ContentType,但必须
For docx files 对于docx文件
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
For doc files 对于文档文件
Response.ContentType = "application/ms-word"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.