因此处无法将代码粘全,故放在我的BLOG里了,烦请过去帮忙看下可否?
http://blog.csdn.net/anyqu/archive/2008/05/16/2451905.aspx

解决方案 »

  1.   

    .xls文件格式?
    提示你打不开?
      

  2.   

    可能是忘记在Page_Load中加入IsPostBack判断了吧
      

  3.   

    我这里有个类,你可以直接使用,试一下可以不.我是用来下载文件的一个类.,要是好用的话~~给分哦~呵呵 /// <summary>
        /// 类名:CContentSave
        /// 类功能:实现文件的下载过程
        /// 
        /// </summary>
       public class CContentSave
        {
           private String path;                         // 存储文件名及保存的路径
           private System.Net.HttpWebResponse response; // 用于从服务器接收数据流的回应
           /// <summary>
           /// 名称:CContentSave
           ///  功能:构造函数
           /// </summary>
           /// <param name="filePath">文件保存路径包括文件名及扩展名</param>
           /// <param name="response">请求下载文件后返回的回应</param>
           public CContentSave(string filePath,System.Net.HttpWebResponse response)
           {
               this.response = response;
               this.path = filePath;
           }
    /// <summary>
    /// 名称:DownloadProcess
    /// 功能:下载文件
    /// </summary>
    /// <returns>0:下载失败;1:下载成功;2:用户取消</returns>
           public int DownloadProcess()
           {
               if (this.response.StatusCode == System.Net.HttpStatusCode.OK)
               {
                   // FrmProgressLA frmProcess = new FrmProgressLA(this.path);
                   long length = this.response.ContentLength;
                   try
                   {                                     System.IO.FileStream file = new System.IO.FileStream(this.path, System.IO.FileMode.Append
                                                                            , System.IO.FileAccess.Write,
                                                                            System.IO.FileShare.Write);
                       System.IO.Stream strm = this.response.GetResponseStream();
                   //    frmProcess.Show();
                       long nowlength = 0;
                       // 开始保存数据流,每次读取4096个字节
                       int readlenth=0;
                       byte[] buffer = new byte[4096];
                       readlenth=strm.Read(buffer,0,4096);
                       while (readlenth>0)
                       {
                            file.Write(buffer, 0, readlenth);
                           readlenth = strm.Read(buffer, 0, buffer.Length);
                           
                           // 此处添加调用设置下载界面的代码                          }
                       // 此处添加 文件下载完毕,关闭下载界面的代码                                   file.Close();
                       return 1;
                   }
                   catch (Exception e)
                   {
                       System.Windows.Forms.MessageBox.Show(e.Message);
                     // 下载失败                   
                       return 0;
                   }
               }
               // 下载失败
               return 0;
           }
        }