【发布时间】:2011-10-30 12:28:41
【问题描述】:
我有一个 Web 应用程序,我需要在其中打开任何标准格式的文件,例如 iframe 中的 .doc/docx/.csv/.txt/.xls 。我怎样才能做到这一点?我尝试使用下面的示例代码,但它没有打开 iframe 中的所有文件格式。我收到一些 XML 错误。
var ext = GetExtension(fileName);
switch (ext)
{
case "pdf":
Response.ContentType = "Application/pdf";
break;
case "htm":
case "html":
Response.ContentType = "text/html";
break;
case "txt":
Response.ContentType = "text/plain";
break;
case "doc":
Response.ContentType = "Application/vnd.ms-word";
break;
case "xls":
case "csv":
Response.ContentType = "Application/vnd.ms-excel";
break;
case "ppt":
case "pps":
Response.ContentType = "Application/vnd.ms-powerpoint";
break;
default:
Response.ContentType = "Application/unknown";
break;
}
if (Response.ContentType != "Application/unknown")
{
Response.Flush();
Response.WriteFile(fileName);
Response.End();
}
【问题讨论】:
-
一件事要尝试,而不是
Response.Flush();使用Response.Clear();