예제 #1
0
파일: FileHelper.cs 프로젝트: SYZhai/WeiBMS
 /// <summary>
 /// base64编码的文本转为图片
 /// </summary>
 /// <param name="photo">base64编码</param>
 /// <param name="filePath">保存绝对路径</param>
 /// <returns></returns>
 public static bool Base64ToImage(string photo, string filePath)
 {
     try
     {
         string dirpath = ConfigHelper.GetValue("SaveFile") + "\\" + DateTime.Now.ToString("yyyyMMdd");//文件保存路径
         if (!Directory.Exists(dirpath))
         {
             Directory.CreateDirectory(dirpath);
         }
         if (File.Exists(filePath))
         {
             File.Delete(filePath);
         }
         byte[]       arr = Convert.FromBase64String(photo);
         MemoryStream ms  = new MemoryStream(arr);
         Bitmap       bmp = new Bitmap(ms);
         bmp.Save(filePath);
         ms.Close();
         return(true);
     }
     catch (Exception e)
     {
         Logger.WriteLog("base64编码的文本转为图片出现异常\r\n" + e.Message + "\r\n base64编码" + photo + "\r\n");
         return(false);
     }
 }
예제 #2
0
 /// <summary>
 /// 创建缓存项过期
 /// </summary>
 /// <param name="key">缓存Key</param>
 /// <param name="obj">object对象</param>
 public static void Insert(string key, object obj)
 {
     if (obj != null)
     {
         int expires = CommonHelper.GetInt(ConfigHelper.GetValue("TimeCache"));
         Insert(key, obj, expires);
     }
 }
예제 #3
0
 /// <summary>
 /// 获取缓存对象
 /// </summary>
 /// <param name="key">缓存Key</param>
 /// <returns>object对象</returns>
 public static object GetCache(string key)
 {
     if (string.IsNullOrEmpty(key))
     {
         return(null);
     }
     if (ConfigHelper.GetValue("IsCache") == "false")
     {
         return(null);
     }
     return(HttpContext.Current.Cache.Get(key));
 }