Esempio n. 1
0
        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="file"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public static string UploadImg(HttpPostedFileBase file, string dir, out string savePath)
        {
            savePath = string.Empty;
            try
            {
                string Image_Path = null;                                                //保存的文件
                Dictionary <string, string> DicInfo = new Dictionary <string, string>(); //返回的文件信息

                //判断上传文件的类型
                string fileName = Path.GetFileName(file.FileName); //获取文件名
                string fileExt  = Path.GetExtension(fileName);     //获取扩展名

                if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
                {
                    //创建文件夹
                    FileOpert.CreateDirectory(dir);
                    //需要对上传的文件进行重命名
                    string newfileName = Guid.NewGuid().ToString();
                    //构建文件完整路径
                    string fullDir = dir + newfileName + fileExt;
                    file.SaveAs(fullDir);  //保存文件
                    savePath = fullDir;
                    return("");
                }
                else
                {
                    return("图片格式不支持!");
                }
            }
            catch (Exception ex)
            {
                return("图片上传失败!");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 根据年月检查创建文件
        /// </summary>
        /// <param name="date">时间标准</param>
        /// <param name="filePath"></param>
        private static void CreateDirectoryByMoth(DateTime date, string filePath)
        {
            //// 先判读年文件夹是否已经创建
            filePath = filePath + "//" + date.ToString("yyyy");
            FileOpert.CheckDirectoryIsExists(filePath, true);

            //// 检查月文件是否已经创建
            filePath = filePath + "//" + date.ToString("MM");
            FileOpert.CheckDirectoryIsExists(filePath, true);
        }
Esempio n. 3
0
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="message"></param>
        public static bool AddMessage(string message)
        {
            try
            {
                //// 记录接收到的微信消息日志
                //// 获取微信消息日志存储位置

                //// 是否记录微信消息日志 1:记录 0:不记录 默认为0
                string isAddWXMessageLog = WebConfigeOpert.GetIsAddWXMessageLog();

                //// 如果不记录日志,那么直接返回
                if (isAddWXMessageLog != "1")
                {
                    return(true);
                }

                //// 微信消息日志记录路径
                string wxMessageLogPath = WebConfigeOpert.GetWXMessageLogPath();

                if (string.IsNullOrEmpty(wxMessageLogPath))
                {
                    return(true);
                }

                DateTime dateNow = System.DateTime.Now;

                //// 检查创建文件夹
                CreateDirectoryByMoth(dateNow, wxMessageLogPath);

                string filePath = string.Format("{0}//{1}//{2}//{3}.txt", wxMessageLogPath, dateNow.ToString("yyyy"), dateNow.ToString("MM"), dateNow.ToString("yyyyMMdd"));
                //// 按照日期创建文件
                CreateFile(filePath);

                //// 写文件
                FileOpert.WriteFile(filePath, message, true);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 4
0
 private static void CreateFile(string filePath)
 {
     //// 先判读年文件夹是否已经创建
     FileOpert.CheckFileIsExists(filePath, true);
 }