Beispiel #1
0
        /// <summary>
        /// 显示文件
        /// </summary>
        /// <param name="filename"></param>
        private void ShowFile(string filename, string name, RequestInfo request, ResponseInfo response)
        {
            FileInfo finf = new FileInfo(filename);

            response.MimeType = WebCommon.GetContentType(finf.Extension.Trim('.'));
            string strName = RequestInfo.GetFileName(request, name);

            response.Header["Content-Disposition"] = "attachment;filename=" + strName;
            long len = finf.Length;

            response.Header["Accept-Ranges"]             = "bytes";
            response.Header["Content-Transfer-Encoding"] = "binary";
            if (request.Header.ContainsKey("range"))                                                     //如果客户端指定了分段下载
            {
                List <RangeInfo> lstRange = ResponseInfo.GetRange(request.Header["Range"], finf.Length); //处理区段信息
                if (lstRange.Count > 0)
                {
                    response.Header["Content-Range"] = "bytes " + lstRange[0].Start + "-" + lstRange[0].End + "/" + finf.Length;//指定区段
                    response.StatusCode = 206;
                }
            }
            try
            {
                response.UserTag     = finf;
                response.Length      = len;
                response.RangeLength = finf.Length;
            }
            catch (Exception ex)
            {
                response.Write("数据读取失败:" + ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 输出文件目录的下载列表
        /// </summary>
        /// <param name="curDir"></param>
        /// <param name="request"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        private bool PutLst(string curDir, RequestInfo request, ResponseInfo response, string url)
        {
            DirectoryInfo dinfo = new DirectoryInfo(curDir);

            if (dinfo.Exists)
            {
                string content = GetDictoryFiles(request, curDir, HttpUtility.HtmlDecode(url));
                response.MimeType = WebCommon.GetContentType("*");
                response.Header["Content-Disposition"] = "attachment;filename=" + HttpUtility.UrlEncode(dinfo.Name) + ".lst";
                response.Header["Connection"]          = "close";

                response.Write(content);
                return(true);
            }
            return(false);
        }