我只是想下载一个文件。但现在我只能下载图像了。
我有这个:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult DownloadFile(DownloadFileModel model, string fileName, int fileId)
{
//var extension = Path.GetExtension(model.FileName).TrimStart('.');
//var extensies = Seneca.SfsLib.FileSystemHelper.UploadOptInExtensions.Contains(extension);
string customerSchema = SfsHelpers.StateHelper.GetSchema();
TemplateLibraryEntry entry = GetTemplateLibraryEntry(model.DesignId, customerSchema);
FileTree tree = CreateTree(model.DesignId, entry.FilePath);
FileInfo fileInfo = new FileInfo(tree.Files[fileId].FullPath);
DirectoryInfo directoryInfo = new DirectoryInfo(tree.Files[fileId].FullPath);
try {
var fs = System.IO.File.OpenRead(fileInfo + model.FileName );
return File(fs, "application/jpg", fileName);
}
catch {
throw new HttpException(404, "Couldn't find " + model.FileName);
}
}
但如果我现在下载一个文件,我每次都会看到下载文件。我的意思是我没有看到电影名称和扩展名
谢谢
答案 0 :(得分:3)
如果您使用的是.NET 4.5或更高版本,则它内置支持直接从文件名中获取MIME类型。
你可以这样做:
return File(fs, System.Web.MimeMapping.GetMimeMapping(fileName), fileName);