考虑到我的文件存储在数据库中,我如何在 asp.net mvc 应用程序中打开 .docx、.doc、.xls 或 .ppt 文件。我可以通过编写以下行在记事本中打开一个 css 文件
return File(("~/Content/Site.css"), ("text/css"));
最佳答案
File 实用程序方法(对于 FileResult)有一个重载,它采用流或字节数组(数据库中的文件可以作为流或字节数组提供。
var bytes = db.GetFile(); //i'm assuming this method will return a byte array
return File(bytes,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document");
要使用特定文件名下载文件,您可以使用另一个重载。
return File(bytes,
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"filename.docx");
关于sql-server - 在 asp.net-mvc 中打开一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14099394/