SmartWeb.cs

        /// <summary>
        /// 文件下载方法
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="filePath">Web 服务器上的指定虚拟路径相对应的物理文件路径</param>
        public static void FileDownLoad(string fileName, string filePath)
        {
            HttpResponse response = HttpContext.Current.Response;
            response.HeaderEncoding = System.Text.Encoding.Default;
            response.ContentType = "application/octet-stream";
            response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));
            response.Clear();
            response.WriteFile(filePath);
            response.End();
        }

        /// <summary>
        /// 文件下载方法
        /// </summary>
        /// <param name="fileName">文件名</param>
        /// <param name="filePath">Web 服务器上的指定虚拟路径相对应的物理文件路径</param>
        /// <param name="encoding">当前标头输出流的编码</param>
        public static void FileDownLoad(string fileName, string filePath, System.Text.Encoding encoding)
        {
            HttpResponse response = HttpContext.Current.Response;
            response.HeaderEncoding = encoding;
            response.ContentType = "application/octet-stream";
            response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));
            response.Clear();
            response.WriteFile(filePath);
            response.End();
        }

posted @ 2009-04-29 16:48  SmartFramework@live.jp  阅读(170)  评论(1编辑  收藏  举报