页面上点击 “下载” 按钮   弹出一个信息提示框  (很常见的那种)  问你是要打开 保存 还是取消
从服务器当一个excel文件到本地。请问怎么做?

解决方案 »

  1.   

    public static void DownloadFile(string physicalFilePath)
    {
    FileStream stream=null;
    stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);    
    int bufSize = (int)stream.Length;
    byte[] buf = new byte[bufSize]; int bytesRead = stream.Read(buf, 0, bufSize);
    HttpContext.Current.Response.ContentType = "application/octet-stream"; 
    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+System.IO.Path.GetFileName(physicalFilePath));
    HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
    HttpContext.Current.Response.End();
    }