FileResult オブジェクトを使用して、Excel でローカル ディスク上の Excel ファイルを開こうとしています。ファイルをクリックして開くと、ActionResult(WTF?) と同じ名前のファイルがダウンロードされ、ダウンロードしたファイルをクリックすると「プログラムの選択」ウィンドウが表示されます。Excel を選択すると、それが開きますが、Excel ファイルとしてダウンロードして追加の手順なしで開くには何が欠けていますか? 以下は、ファイルを開くための私のスイッチステートメントです。ありがとう
public ActionResult GetFile(string path)
{
string extension = new FileInfo(path).Extension;
if (extension != null || extension != string.Empty)
{
switch (extension)
{
case ".pdf":
return File(path, "application/pdf");
case ".txt":
return File(path, "application/plain");
case ".jpeg":
return File(path, "application/jpeg");
case ".doc":
return File(path, "application/msword");
case ".docx":
return File(path, "application/msword");
case ".xls":
return File(path, "application/msexcel");
case ".xlsx":
return File(path, "application/msexcel");
default:
return File(path, "application/octet-stream");
}
}
return View("Index");
}