首页 新闻 会员 周边 捐助

Net 下载Excel模板时报404 - �Ҳ����ļ���Ŀ¼��

0
[已解决问题] 解决于 2018-10-19 14:10

代码:

/// <summary>
/// 下载导入模板
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ExportBiaoZhun_Click(object sender, EventArgs e)
{
string strFilePath = Server.MapPath("~") + "/ZSK/问题上传模板.xls";//服务器文件路径
FileInfo fileInfo = new FileInfo(strFilePath);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
string agent = "";
//string filename = "";
agent = Request.UserAgent;
//if (agent != null && agent != "" && agent.IndexOf("Edge") < 0)
//{
// filename = fileInfo.Name;
//}
//else
//{
// filename = Uri.EscapeDataString(fileInfo.Name);
//}

    string name = fileInfo.Name;
    if (Request.UserAgent.ToLower().IndexOf("msie") > -1) //ie浏览器
    {
        name = HttpUtility.UrlEncode(name, System.Text.Encoding.UTF8);
    }
    if (Request.UserAgent.ToLower().IndexOf("firefox") > -1) //火狐浏览器
    {
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + name + "\"");
    }
    else //其他浏览器,如谷歌浏览器
    {
        Response.AddHeader("Content-Disposition", "attachment;filename=" + name);
    }

    Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    Response.ContentType = "application/x-bittorrent";
    Response.Charset = "utf-8";
    Response.WriteFile(fileInfo.FullName);
    Response.End();
}

在本地和测试站都ok,发布到正式站就成这样了,大神们是时候展现你们真正技术了!!!

耶夫托拉斯基的主页 耶夫托拉斯基 | 初学一级 | 园豆:94
提问于:2018-09-21 11:18
< >
分享
最佳答案
0

试试 Response.ContentType = "application/vnd.ms-excel";

奖励园豆:5
dudu | 高人七级 |园豆:29568 | 2018-09-21 11:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册