我用ASP。NET做的文件上传的程序,代码如下:
private void FileDownload(string FullFileName)
{
FileInfo DownloadFile=new FileInfo(FullFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType="application/octet-stream";
Response.AppendHeader("Content-Disposition",
"attachment;filename="+
HttpUtility.UrlEncode(DownloadFile.FullName,
System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
} private void Button1_Click(object sender, System.EventArgs e)
{
FileDownload(@"D:\file\1.EXCEL");
}
为什么别人在打开的时候EXCEL会弹出个对话框找不到'C:\Documents and Settings\Guest\Local Settings\Temporary Internet Files\Content.IE5\D%3a%5c\file\%5c%2d\1.EXCEL'.请检查档名是否有拼错或文件是否存在!

解决方案 »

  1.   

    try this:string s=".....";
    System.IO.StringWriter sw = new System.IO.StringWriter();
            sw.WriteLine(s);
            Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmdd") + ".xls");
            Response.ContentType = "application/ms-excel";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            Response.Write(sw);
            Response.End();
      

  2.   

    路径不对。D:\file\1.EXCEL。这个里的‘\’‘:’‘。’都被替换成\%5c%2d了。应该转换一下。
      

  3.   

    System.Web.HttpUtility.UrlDecode("str");
      

  4.   

    可是!有些人可以的打的开啊!也不是程序调试的出错,而是客户端他的EXCEL打开的时候才会弹出个对话框说EXCEL找不到到'C:\Documents and Settings\Guest\Local Settings\Temporary Internet Files\Content.IE5\D%3a%5c\file\%5c%2d\1.EXCEL'.有时候如果文件名字很长比如vvvvvvvvvvvvvvv.xsl我在服务器上把名字改成v.xsl客户端就可以的打的开啊!我郁闷的要死!难道大家都没有遇到过这样的问题吗?