Пример #1
0
        //#region DownFile/ResponseFile/GetHttpFile
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="fileFile">文件路径(绝对路径)</param>
        /// <param name="newFileName">新文件名.扩展名(无路径)</param>
        /// <returns >返回文件是否存在,存在下载成功</returns>
        public static bool ResponseFile(string fileFile, string newFileName = "")
        {
            if (System.IO.File.Exists(fileFile))
            {
                FileInfo _DownloadFile = new FileInfo(fileFile);
                newFileName = string.IsNullOrEmpty(newFileName) ? _DownloadFile.FullName : newFileName;
                if (Request2.GetBrowser().ToLower().IndexOf("ie") != -1)
                {
                    newFileName = HttpUtility.UrlEncode(newFileName, System.Text.Encoding.UTF8);
                }
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.Buffer      = false;
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + newFileName);
                HttpContext.Current.Response.AppendHeader("Content-Length", _DownloadFile.Length.ToString());
                HttpContext.Current.Response.WriteFile(_DownloadFile.FullName);
                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.End();
                return(true);
            }

            return(false);
        }
Пример #2
0
        //#endregion
        //#region 错误消息
        /// <summary>
        /// 显示详细的出错信息
        /// </summary>
        /// <param name="ex">Exception ex</param>
        /// <returns></returns>
        public static string Expand(Exception ex)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("*******************************************************************************************************");
            if (!HttpContext.Current.IsNull())
            {
                sb.AppendLine(string.Format("* DateTime :   {0}	IP:{1}	MemberID:{2}	OS:{3}	Brower:{4}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Request2.GetIP(), "", Request2.GetOS(), Request2.GetBrowser()));
                sb.AppendLine("* Url      :   " + Request2.GetUrl());
                sb.AppendLine("* Request  :   " + Request2.GetRequest());
            }
            _expandException(ex, 1, sb);
            sb.AppendLine("*******************************************************************************************************");
            sb.AppendLine("");
            return(sb.ToString());
        }
Пример #3
0
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="msg">消息</param>
        /// <param name="encoding">编码</param>
        /// <returns>true/false</returns>
        public bool Write(string msg, Encoding encoding = null)
        {
            string        LogFile = LogPath.TrimEnd('\\') + @"\Log_" + DateTime.Now.ToString("yyyyMMdd") + ".log";
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine("/*******************************************************************************************************");
            sb.AppendLine(string.Format("* DateTime:{0}{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), HttpContext.Current.IsNotNull() ? ("	IP:{0}	OS:{1}	Brower:{2}".FormatWith(Request2.GetIP(), Request2.GetOS(), Request2.GetBrowser())) : ""));
            if (HttpContext.Current.IsNotNull())
            {
                sb.AppendLine("* Url:" + Request2.GetUrl());
                sb.AppendLine("* Data:" + Request2.GetRequestInputStream());
            }
            sb.AppendLine("* Message:" + msg);
            sb.AppendLine("*******************************************************************************************************/");
            sb.AppendLine("");
            return(FileDirectory.FileWrite(LogFile, sb.ToString(), encoding ?? Encoding.UTF8));
        }