public CustomFileInfo UpLoadFileInfo(CustomFileInfo fileInfo) { log.Info("上传文件开始:" + DateTime.Now); byte[] bytes = Convert.FromBase64String(fileInfo.SendByteStr); string fileName = CommonUtil.GUID() + fileInfo.Extension; //log.Info("newbytes:" + newbytes); log.Info("图片名字:" + fileName); string fullpath = HttpContext.Current.Server.MapPath("~/Upload/") + fileName; using (FileStream fileStream = new FileStream(fullpath, FileMode.Create)) { fileStream.Write(bytes, 0, bytes.Length); } fileInfo.OldName = fileInfo.OldName; fileInfo.NewName = fileName; fileInfo.Extension = fileInfo.Extension; fileInfo.Path = "/Upload/" + fileName; fileInfo.FileSize = FileUtil.GetFileSize(fullpath).ToString(); fileInfo.SendByte = null; log.Info("上传文件结束:" + DateTime.Now); return(fileInfo); }
public CustomFileInfo DeleteFile(CustomFileInfo fileInfo) { try { string fullpath = HttpContext.Current.Server.MapPath("~/Upload/") + fileInfo.NewName; if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); } fileInfo.State = 0; } catch (Exception) { fileInfo.State = 0; } return(fileInfo); }