/// <summary> /// 下载头像3 /// 检查头像名称 /// </summary> /// <param name="path"></param> /// <param name="uid"></param> /// <param name="imgName"></param> /// <returns></returns> public static byte[] DownLoad_Head_3(string path, string uid, string imgName) { //判断本地是否存在头像图片 string savePath = AppDomain.CurrentDomain.BaseDirectory + headImgMainPath + "{0}" + headImgDirName + "{1}"; savePath = string.Format(savePath, new string[] { uid, imgName }); byte[] headImage = null; if (File.Exists(savePath)) //本地存在,直接获取本地 { headImage = File.ReadAllBytes(savePath); // return(headImage); } else { string defaultPath = AppDomain.CurrentDomain.BaseDirectory + defaultImgPath; using (NewWebClient wc = new NewWebClient(3 * 1000)) { try { if (!Directory.Exists(headImgMainPath + uid)) { Directory.CreateDirectory(headImgMainPath + uid); } if (!Directory.Exists(headImgMainPath + uid + headImgDirName)) { Directory.CreateDirectory(headImgMainPath + uid + headImgDirName); } string headImageUrl = path; headImage = wc.DownloadData(headImageUrl); File.WriteAllBytes(savePath, headImage); return(headImage); } catch (Exception ex) { //result = true; return(null); //throw; } finally { } } } }
/// <summary> /// 下载文件 /// </summary> /// <param name="path"></param> /// <param name="uid"></param> /// <returns></returns> public static bool Download_Head(string path, string uid, ref byte[] headImage) { bool result = true; string savePath = AppDomain.CurrentDomain.BaseDirectory + headImgMainPath + "{0}" + headImgDirName + "{1}"; savePath = string.Format(savePath, new string[] { uid, SysParams.Sys_DefaultHeadImageFileName }); string defaultPath = AppDomain.CurrentDomain.BaseDirectory + defaultImgPath; //byte[] b; using (NewWebClient wc = new NewWebClient(1 * 1000)) { try { if (!Directory.Exists(headImgMainPath + uid)) { Directory.CreateDirectory(headImgMainPath + uid); } if (!Directory.Exists(headImgMainPath + uid + headImgDirName)) { Directory.CreateDirectory(headImgMainPath + uid + headImgDirName); } string headImageUrl = path; headImage = wc.DownloadData(headImageUrl); File.WriteAllBytes(savePath, headImage); } catch (Exception ex) { result = true; //throw; } finally { if (headImage == null) { headImage = File.ReadAllBytes(defaultPath); } } } return(result); }