/// <summary> /// 添加用户证件信息 /// </summary> /// <param name="entity"></param> public void addUserCertificate(UserCertificateEntity entity, FileInfoEntity file) { var db = new RepositoryFactory().BaseRepository().BeginTrans(); try { var oldfiles = (from q in db.IQueryable <FileInfoEntity>() where q.RecId == entity.Id & q.Description != "成员证书二维码" select q).ToList(); if (entity.Files != null) { var deletefiles = oldfiles.Except(entity.Files).ToList(); db.Delete(deletefiles); var newfiles = entity.Files.Except(oldfiles).ToList(); db.Insert(newfiles); } entity.Files = null; if (file != null) { file.RecId = entity.Id; file.State = null; db.Update(file); } db.Insert(entity); db.Commit(); } catch (Exception ex) { db.Rollback(); throw; } }
public ActionResult CopyForm(string keyValue, string Fileid) { StaffinformcardEntity data = staffinformcardbll.GetEntity(keyValue);//先根据id获取实体 data.CardType = 0; data.Id = System.Guid.NewGuid().ToString(); staffinformcardbll.SaveForm("", data); //进行新增 FileInfoBLL file = new FileInfoBLL(); FileInfoEntity fi = file.GetEntity(Fileid); //获取文件信息 string oldfilename = fi.FilePath.Substring(fi.FilePath.LastIndexOf('/') + 1); string url = fi.FilePath.Substring(1, fi.FilePath.LastIndexOf('/') + 1); //不要~ string[] filenames = oldfilename.Split('.'); if (filenames.Length > 1) { string hz = filenames[filenames.Length - 1];//后缀名 string newfilename = System.Guid.NewGuid().ToString() + "." + hz; string newUrl = url + newfilename; string oldPath = fi.FilePath.Substring(1); CopyFile(oldPath, newUrl);//复制到新地址 fi.FileId = ""; fi.RecId = data.Id; fi.FilePath = "~" + newUrl; //加入记录时加上~ file.SaveForm("", fi); //生成新的文件记录 return(Success("true")); } return(Success("false")); }
/// <summary> /// 下载 /// </summary> /// <param name="keyValue"></param> /// <param name="filename"></param> /// <param name="recId"></param> public void DownloadFile(string keyValue, string filename, string recId) { var fileFolderBLL = new FileFolderBLL(); var fileInfoBLL = new FileInfoBLL(); if (string.IsNullOrEmpty(keyValue)) { return; } FileInfoEntity data = null; if (!string.IsNullOrEmpty(filename)) { data = fileInfoBLL.GetEntity(recId, Server.UrlDecode(filename)); } else { data = fileInfoBLL.GetEntity(keyValue); } if (data != null) { string name = string.IsNullOrEmpty(filename) ? Server.UrlDecode(data.FileName) : Server.UrlDecode(filename);//返回客户端文件名称 string filepath = this.Server.MapPath(data.FilePath); if (FileDownHelper.FileExists(filepath)) { FileDownHelper.DownLoadold(filepath, name); } } }
public FtpTaskUserControl(FileInfoEntity info) { InitializeComponent(); this.Dispatcher.Invoke(delegate { pBar.Value = (int)info.OperationProgress; }); _FtpHelper = new FtpHelper(info); tblockFileName.Text = info.FileName; _FtpHelper.Started += _FtpHelper_Started; _FtpHelper.Paused += _FtpHelper_Paused; _FtpHelper.Resumed += _FtpHelper_Resumed; _FtpHelper.Cancelled += _FtpHelper_Cancelled; _FtpHelper.Failed += _FtpHelper_Failed; _FtpHelper.ProgressUpdated += _FtpHelper_ProgressUpdated; _FtpHelper.Done += _FtpHelper_Done; //用户控件销毁前处理 Dispatcher.ShutdownStarted += (object sender, EventArgs e) => { if (_FtpHelper.TaskThread != null) { _FtpHelper.TaskThread.Abort(); _FtpHelper.TaskThread = null; } }; }
public void DownloadFile(string keyValue, string filename, string recId) { if (string.IsNullOrEmpty(keyValue)) { return; } FileInfoEntity data = null; if (!string.IsNullOrEmpty(filename)) { data = fileInfoBLL.GetEntity(recId, Server.UrlDecode(filename)); } else { data = fileInfoBLL.GetEntity(keyValue); } if (data != null) { string name = string.IsNullOrEmpty(filename) ? Server.UrlDecode(data.FileName) : Server.UrlDecode(filename);//返回客户端文件名称 string filepath = this.Server.MapPath(data.FilePath); if (FileDownHelper.FileExists(filepath)) { FileDownHelper.DownLoadold(filepath, name); } else { Response.StatusCode = 404; Response.Redirect("../../Error/ErrorPath404", true); return; } } }
public ActionResult PostFile(string postData, string keyValue) { FileInfoEntity fileInfoEntity = new FileInfoEntity(); FileInfoBLL fileInfoBLL = new FileInfoBLL(); var dt = JsonConvert.DeserializeObject <List <FileInfoEntity> >(postData); List <FileInfoEntity> projects = dt; string dir = string.Format("~/Resource/{0}/{1}", "ht/images", DateTime.Now.ToString("yyyyMMdd")); foreach (FileInfoEntity item in dt) { var filepath = Server.MapPath(item.FilePath); if (System.IO.File.Exists(filepath)) { string newFileName = Guid.NewGuid().ToString() + item.FileExtensions; string newFilePath = dir + "/" + newFileName; System.IO.File.Copy(filepath, Server.MapPath(newFilePath)); } item.RecId = keyValue; item.FileId = Guid.NewGuid().ToString(); fileInfoBLL.SaveForm("", item); } //fileInfoBLL.SaveForm("", fileInfoEntity); return(Success("操作成功。")); }
private void btnSure_Click(object sender, RoutedEventArgs e) { FileInfoEntity info = new FileInfoEntity(); string path = tbLocalPath.Text; info.FilePath = path.Substring(0, path.LastIndexOf("\\")); info.FileName = path.Substring(info.FilePath.Length + 1, path.Length - info.FilePath.Length - 1); info.NewFilePath = ""; info.NewFileName = tbRomteFile.Text; info.FileType = FileType.File; if (FtpHelper.CheckExistOfRemoteFile("ftp://" + FtpHelper.IP + "/" + (string.IsNullOrEmpty(info.NewFilePath) ? "" : info.NewFilePath + "/") + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件已存在"); } else { this.Close(); FtpHelper.TaskInit(info); FtpTaskUserControl taskControl = new FtpTaskUserControl(info); taskControl.btnRun.Content = info.ResultCode == ResultCode.New ? "Wait" : "Run"; taskControl.mainWindow = mainWindow; mainWindow.lv.Items.Add(taskControl); mainWindow.TaskSum++; mainWindow.ReflashUI(); } }
private void btnSure_Click(object sender, RoutedEventArgs e) { FileInfoEntity info = new FileInfoEntity(); string path = tbLocalPath.Text; info.FilePath = path.Substring(0, path.LastIndexOf("\\")); info.FileName = path.Substring(info.FilePath.Length + 1, path.Length - info.FilePath.Length - 1); info.NewFilePath = ""; info.NewFileName = tbRomteFile.Text; info.FileType = FileType.File; if (FtpHelper.CheckExistOfRemoteFile("ftp://" + FtpHelper.IP + "/" + (string.IsNullOrEmpty(info.NewFilePath) ? "" : info.NewFilePath + "/") + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件已存在"); } else { this.Close(); if (MainWindow.uploadForm == null || MainWindow.uploadForm.IsDisposed) { MainWindow.uploadForm = new FtpUploadListForm(); MainWindow.uploadForm.Done += (s, ex) => { }; MainWindow.uploadForm.Init(); } FtpHelper.TaskInit(info); MainWindow.uploadForm.Add(info); MainWindow.uploadForm.WindowState = System.Windows.Forms.FormWindowState.Normal; MainWindow.uploadForm.Show(); } }
public ActionResult PostFile(string postData, string keyValue) { FileInfoEntity fileInfoEntity = new FileInfoEntity(); FileInfoBLL fileInfoBLL = new FileInfoBLL(); fileInfoBLL.DeleteFileByRecId(keyValue);//删除原有附件 var dt = JsonConvert.DeserializeObject <List <FileInfoEntity> >(postData); List <FileInfoEntity> projects = dt; string dir = string.Format("~/Resource/{0}/{1}", "ht/images", DateTime.Now.ToString("yyyyMMdd")); if (Directory.Exists(Server.MapPath(dir)) == false)//如果不存在就创建文件夹 { Directory.CreateDirectory(Server.MapPath(dir)); } foreach (FileInfoEntity item in dt) { var filepath = Server.MapPath(item.FilePath); if (System.IO.File.Exists(filepath)) { string sufx = System.IO.Path.GetExtension(filepath); string newFileName = Guid.NewGuid().ToString() + sufx; string newFilePath = dir + "/" + newFileName; System.IO.File.Copy(filepath, Server.MapPath(newFilePath)); item.FilePath = newFilePath; } item.RecId = keyValue; item.FileId = Guid.NewGuid().ToString(); fileInfoBLL.SaveForm("", item); } fileInfoBLL.SaveForm("", fileInfoEntity); return(Success("操作成功。")); }
private void btnSure_Click(object sender, RoutedEventArgs e) { FileInfoEntity info = new FileInfoEntity(); string path = tbLocalPath.Text; info.FilePath = path.Substring(0, path.LastIndexOf("\\")); info.FileName = path.Substring(info.FilePath.Length + 1, path.Length - info.FilePath.Length - 1); info.NewFilePath = ""; info.NewFileName = tbRomteFile.Text; info.FileType = FileType.Directory; if (FtpHelper.CheckExistOfRemoteDirectory("ftp://" + FtpHelper.IP + "/" + (string.IsNullOrEmpty(info.NewFilePath) ? "" : info.NewFilePath + "/") + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件夹已存在"); } else { this.Close(); if (MainWindow.uploadForm == null || MainWindow.uploadForm.IsDisposed) { MainWindow.uploadForm = new FtpUploadListForm(); MainWindow.uploadForm.Init(); } List <FileInfoEntity> subDirList = new List <FileInfoEntity>(); List <FileInfoEntity> ls = FtpHelper.TaskInit(info).Where(x => x.FileType == FileType.File).Select(x => { return(x); }).ToList(); if (ls != null) { foreach (FileInfoEntity item in ls) { MainWindow.uploadForm.Add(item); } } MainWindow.uploadForm.WindowState = FormWindowState.Normal; MainWindow.uploadForm.Show(); } }
private void btnSure_Click(object sender, RoutedEventArgs e) { string path = comBox.SelectedValue.ToString(); FileInfoEntity info = new FileInfoEntity(); info.Method = Method.Download; info.FileType = FileType.Directory; info.FilePath = path.Contains("/") ? path.Substring(0, path.LastIndexOf("/")) : ""; info.FileName = path.Contains("/") ? path.Substring(path.LastIndexOf("/") + 1, path.Length - path.LastIndexOf("/") - 1) : path; info.NewFilePath = tbLocalPath.Text; info.NewFileName = tbDirName.Text; if (Directory.Exists(info.NewFilePath + "\\" + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件夹已存在"); } else { this.Close(); List <FileInfoEntity> ls = FtpHelper.TaskInit(info).Where(x => x.FileType == FileType.File).Select(x => { return(x); }).ToList(); foreach (FileInfoEntity item in ls) { FtpTaskUserControl taskControl = new FtpTaskUserControl(item); taskControl.btnRun.Content = item.ResultCode == ResultCode.New ? "Wait" : "Run"; taskControl.mainWindow = mainWindow; mainWindow.DownloadTaskSum++; mainWindow.lvDownload.Items.Add(taskControl); } mainWindow.ReflashUI(); } }
private static string UploadFile(FileInfoEntity entity) { string errorMsg = null; IFormatter formatter = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); formatter.Serialize(ms, entity); ms.Position = 0; var content = HttpContent.Create(ms, "application/octet-stream", ms.Length); var client = new HttpClient(); using (var response = client.Post(uploadUri, content)) { if (response.StatusCode == HttpStatusCode.OK) { response.Content.LoadIntoBuffer(); } else { errorMsg = response.Content.ReadAsString(); Regex rg = new Regex(@"<P><B>Details[::][\s]*<\/B>([^\/]+)</P>"); if (rg.Match(errorMsg).Success) { errorMsg = rg.Match(errorMsg).Result("$1"); } } } return(errorMsg); }
/// <summary> /// 下载文件 /// </summary> /// <param name="file"></param> /// <returns></returns> public static bool DownLoad(FileInfoEntity file) { try { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(file.FileAddress); request.Method = WebRequestMethods.Ftp.DownloadFile; request.UseBinary = true; request.UsePassive = false; request.Credentials = new NetworkCredential(ConfigInfo.FtpUid, ConfigInfo.FtpPwd); request.KeepAlive = false; using (Stream stream = request.GetResponse().GetResponseStream()) { using (Stream fileStream = new FileStream(string.Format(@"{0}\{1}", ConfigInfo.DocDirName, file.FileName), FileMode.Create, FileAccess.Write)) { byte[] bytes = new byte[1024 * 4]; int size = stream.Read(bytes, 0, bytes.Length); while (size > 0) { fileStream.Write(bytes, 0, size); size = stream.Read(bytes, 0, bytes.Length); } fileStream.Flush(); fileStream.Close(); stream.Close(); return(true); } } } catch { return(false); } }
private void btnSure_Click(object sender, RoutedEventArgs e) { string path = comBox.SelectedValue.ToString(); FileInfoEntity info = new FileInfoEntity(); info.Method = Method.Download; info.FileType = FileType.File; info.FilePath = path.Contains("/") ? path.Substring(0, path.LastIndexOf("/")) : ""; info.FileName = path.Contains("/") ? path.Substring(path.LastIndexOf("/") + 1, path.Length - path.LastIndexOf("/") - 1) : path; info.NewFilePath = tbLocalPath.Text; info.NewFileName = tbDirName.Text; if (File.Exists(info.NewFilePath + "\\" + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件已存在"); } else { this.Close(); if (MainWindow.downloadForm == null || MainWindow.downloadForm.IsDisposed) { MainWindow.downloadForm = new FtpDownloadListForm(); MainWindow.downloadForm.Done += (s, ex) => { }; MainWindow.downloadForm.Init(); } FtpHelper.TaskInit(info); MainWindow.downloadForm.Add(info); MainWindow.downloadForm.WindowState = System.Windows.Forms.FormWindowState.Normal; MainWindow.downloadForm.Show(); } }
private void btnSure_Click(object sender, RoutedEventArgs e) { FileInfoEntity info = new FileInfoEntity(); string path = tbLocalPath.Text; info.FilePath = path.Substring(0, path.LastIndexOf("\\")); info.FileName = path.Substring(info.FilePath.Length + 1, path.Length - info.FilePath.Length - 1); info.NewFilePath = ""; info.NewFileName = tbRomteFile.Text; info.FileType = FileType.Directory; if (FtpHelper.CheckExistOfRemoteDirectory("ftp://" + FtpHelper.IP + "/" + (string.IsNullOrEmpty(info.NewFilePath) ? "" : info.NewFilePath + "/") + info.NewFileName)) { System.Windows.MessageBox.Show("目标文件夹已存在"); } else { this.Close(); List <FileInfoEntity> subDirList = new List <FileInfoEntity>(); List <FileInfoEntity> ls = FtpHelper.TaskInit(info).Where(x => x.FileType == FileType.File).Select(x => { return(x); }).ToList(); foreach (FileInfoEntity item in ls) { FtpTaskUserControl taskControl = new FtpTaskUserControl(item); taskControl.btnRun.Content = item.ResultCode == ResultCode.New ? "Wait" : "Run"; taskControl.mainWindow = mainWindow; mainWindow.TaskSum++; mainWindow.lv.Items.Add(taskControl); } mainWindow.ReflashUI(); } }
public FtpDownUploadFileUserControl(FileInfoEntity info) { InitializeComponent(); _Info = info; _FtpHelper = new FtpHelper(info); Init(); }
public ActionResult UploadFileNew(string uptype, string id) { FileInfoBLL fileBll = new FileInfoBLL(); IList <FileInfoEntity> fl = fileBll.GetFilesByRecIdNew(id).Where(x => x.Description == uptype).ToList(); foreach (FileInfoEntity fe in fl) { string filepath = fileBll.Delete(fe.FileId); if (!string.IsNullOrEmpty(filepath) && System.IO.File.Exists(Server.MapPath("~" + filepath))) { System.IO.File.Delete(Server.MapPath("~" + filepath)); } } HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; //没有文件上传,直接返回 if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName)) { return(HttpNotFound()); } string FileEextension = Path.GetExtension(files[0].FileName); string type = files[0].ContentType; if (uptype == "0" && !type.Contains("image")) //图片 { return(Success("1")); } if (uptype == "1" && !type.Contains("mp4")) { return(Success("1")); } string Id = OperatorProvider.Provider.Current().UserId; Id = Guid.NewGuid().ToString(); string virtualPath = string.Format("~/Content/AndroidMenufile/{0}{1}", Id, FileEextension); string fullFileName = Server.MapPath(virtualPath); //创建文件夹,保存文件 string path = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path); files[0].SaveAs(fullFileName); FileInfoEntity fi = new FileInfoEntity { FileId = Id, FolderId = id, RecId = id, FileName = System.IO.Path.GetFileName(files[0].FileName), FilePath = virtualPath, FileType = FileEextension.Substring(1, FileEextension.Length - 1), FileExtensions = FileEextension, FileSize = files[0].ContentLength.ToString(), DeleteMark = 0, Description = uptype }; fileBll.SaveForm(fi); return(Success("上传成功。", new { path = Url.Content(virtualPath), name = fi.FileName })); }
public ActionResult UploadifyFile(string folderId, HttpPostedFileBase Filedata) { try { Thread.Sleep(500);////延迟500毫秒 //没有文件上传,直接返回 if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.ContentLength == 0) { if (Request.Files.Count > 0) { Filedata = Request.Files[0]; } else { return(HttpNotFound()); } } //获取文件完整文件名(包含绝对路径) //文件存放路径格式:/Resource/ResourceFile/{userId}{data}/{guid}.{后缀名} string userId = LoginUserInfo.Get().userId; string fileGuid = Guid.NewGuid().ToString(); long filesize = Filedata.ContentLength; string FileEextension = Path.GetExtension(Filedata.FileName); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string virtualPath = string.Format("~/Resource/DocumentFile/{0}/{1}/{2}{3}", userId, uploadDate, fileGuid, FileEextension); string fullFileName = this.Server.MapPath(virtualPath); //创建文件夹 string path = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path); if (!System.IO.File.Exists(fullFileName)) { //保存文件 Filedata.SaveAs(fullFileName); //文件信息写入数据库 FileInfoEntity fileInfoEntity = new FileInfoEntity(); fileInfoEntity.Create(); fileInfoEntity.F_FileId = fileGuid; if (!string.IsNullOrEmpty(folderId)) { fileInfoEntity.F_FolderId = folderId; } else { fileInfoEntity.F_FolderId = "0"; } fileInfoEntity.F_FileName = Filedata.FileName; fileInfoEntity.F_FilePath = virtualPath; fileInfoEntity.F_FileSize = filesize.ToString(); fileInfoEntity.F_FileExtensions = FileEextension; fileInfoEntity.F_FileType = FileEextension.Replace(".", ""); fileInfoBLL.SaveForm("", fileInfoEntity); } return(Success("上传成功。")); } catch (Exception ex) { return(Fail(ex.Message)); } }
/// <summary> /// 图片上传 /// </summary> /// <param name="folderId"></param> /// <param name="Filedata"></param> public string UploadifyFile(string folderId, string filekey, HttpFileCollection fileList) { string filePaths = string.Empty; try { if (fileList.Count > 0) { for (int i = 0; i < fileList.AllKeys.Length; i++) { if (fileList.AllKeys[i].StartsWith(filekey)) { HttpPostedFile file = fileList[i]; //获取文件完整文件名(包含绝对路径) //文件存放路径格式:/Resource/ResourceFile/{userId}{data}/{guid}.{后缀名} string userId = OperatorProvider.Provider.Current().UserId; string fileGuid = Guid.NewGuid().ToString(); long filesize = file.ContentLength; string FileEextension = Path.GetExtension(file.FileName); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string virtualPath = string.Format("~/Resource/ht/images/{0}/{1}{2}", uploadDate, fileGuid, FileEextension); string virtualPath1 = string.Format("/Resource/ht/images/{0}/{1}{2}", uploadDate, fileGuid, FileEextension); string fullFileName = dataitemdetailbll.GetItemValue("imgPath") + virtualPath1; //创建文件夹 string path = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path); FileInfoEntity fileInfoEntity = new FileInfoEntity(); if (!System.IO.File.Exists(fullFileName)) { //保存文件 file.SaveAs(fullFileName); //文件信息写入数据库 fileInfoEntity.Create(); fileInfoEntity.FileId = fileGuid; fileInfoEntity.RecId = folderId; //关联ID fileInfoEntity.FolderId = "ht/images"; fileInfoEntity.FileName = file.FileName; fileInfoEntity.FilePath = virtualPath; fileInfoEntity.FileSize = filesize.ToString(); fileInfoEntity.FileExtensions = FileEextension; fileInfoEntity.FileType = FileEextension.Replace(".", ""); fileInfoBLL.SaveForm("", fileInfoEntity); filePaths += "," + virtualPath; } } } if (!string.IsNullOrEmpty(filePaths)) { return(filePaths.Substring(1)); } } } catch (Exception ex) { } return(filePaths); }
public JsonResult ImportEditPush(string keyvalue) { var success = true; var message = string.Empty; try { string newFilePath = ""; if (this.Request.Files.Count == 0) { throw new Exception("请上传文件"); } var file = this.Request.Files[0]; string fileName = System.IO.Path.GetFileName(file.FileName); if (!fileName.Contains(".pdf")) { throw new Exception("请检查文件格式!"); } string fileGuid = Guid.NewGuid().ToString(); long filesize = file.ContentLength; string FileEextension = Path.GetExtension(fileName); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string dir = string.Format("~/Resource/{0}/{1}", "SevenS", uploadDate); string newFileName = fileGuid + FileEextension; newFilePath = dir + "/" + newFileName; if (!Directory.Exists(Server.MapPath(dir))) { Directory.CreateDirectory(Server.MapPath(dir)); } FileInfoEntity fileInfoEntity = new FileInfoEntity(); if (!System.IO.File.Exists(Server.MapPath(newFilePath))) { //保存文件 file.SaveAs(Server.MapPath(newFilePath)); //文件信息写入数据库 fileInfoEntity.Create(); fileInfoEntity.FolderId = "SevenS"; fileInfoEntity.FileId = fileGuid; fileInfoEntity.RecId = keyvalue; fileInfoEntity.FileName = fileName; fileInfoEntity.FilePath = dir + "/" + newFileName; fileInfoEntity.FileSize = (Math.Round(decimal.Parse(filesize.ToString()) / decimal.Parse("1024"), 2)).ToString();//文件大小(kb) fileInfoEntity.FileExtensions = FileEextension; fileInfoEntity.FileType = FileEextension.TrimStart('.'); FileInfoBLL fileInfoBLL = new FileInfoBLL(); fileInfoBLL.SaveForm("", fileInfoEntity); } message = fileInfoEntity.FileName; } catch (Exception ex) { success = false; message = HttpUtility.JavaScriptStringEncode(ex.Message); } return(Json(new { success, message })); }
/// <summary> /// 添加任务 /// </summary> public void Add(FileInfoEntity info) { if (!_IsInit) { MessageBox.Show("请先初始化FtpListForm再添加任务"); return; } ftpListUserControl1.Add(info); }
public void Add(FileInfoEntity fileToAdd) { if (fileToAdd == null) { throw new ArgumentNullException(nameof(fileToAdd)); } _context.Add(fileToAdd); }
public ActionResult UploadFileNew(string keyValue, int packType) { FileInfoBLL fileBll = new FileInfoBLL(); HttpFileCollection files = System.Web.HttpContext.Current.Request.Files; //没有文件上传,直接返回 if (files[0].ContentLength == 0 || string.IsNullOrEmpty(files[0].FileName)) { return(HttpNotFound()); } string FileEextension = Path.GetExtension(files[0].FileName); if (!FileEextension.Contains("apk")) { return(Success("1")); } string Id = Guid.NewGuid().ToString(); string virtualPath = string.Format("~/Resource/Package/{0}/{1}{2}", packType, Id, FileEextension); string fullFileName = Server.MapPath(virtualPath); //创建文件夹,保存文件 string path = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path); files[0].SaveAs(fullFileName); //保存一个固定的路径 string staticFileName = string.Empty; staticFileName = packType == 0 ? "bzapp.apk" : "bzzdapp.apk"; string staticFilePath = Server.MapPath(string.Format("~/Resource/Package/{0}/{1}", packType, staticFileName)); files[0].SaveAs(staticFilePath); FileInfoEntity fi = new FileInfoEntity { FileId = Id, FolderId = keyValue, RecId = keyValue, FileName = System.IO.Path.GetFileName(files[0].FileName), FilePath = virtualPath, FileType = FileEextension.Substring(1, FileEextension.Length - 1), FileExtensions = FileEextension, FileSize = files[0].ContentLength.ToString(), DeleteMark = 0, Description = packType == 0 ? "安卓APP" : "安卓终端" }; fileBll.SaveForm(fi); var filelist = fileBll.GetFilesByRecIdNew(keyValue); foreach (FileInfoEntity f in filelist) { f.FilePath = Url.Content(f.FilePath); } return(Success("上传成功。", new { path = virtualPath.TrimStart('~'), name = fi.FileName, files = filelist, newpath = Url.Content(virtualPath) })); }
public async Task <string> InsertAsync(FileModel fileInfo, Guid campaignContentId) { var entity = new FileInfoEntity(GetPartitionKey(campaignContentId.ToString()), GetRowKey()); _mapper.Map(fileInfo, entity); await _storage.InsertAsync(entity); return(entity.RowKey); }
public static FileInfoModel ToModel(this FileInfoEntity entity) { return(new FileInfoModel { LastModifiedDate = entity.LastModifiedDate, Name = entity.Name, Size = entity.Size, Type = entity.Type }); }
/// <summary> /// 保存文件信息表单(新增、修改) /// </summary> /// <param name="keyValue">主键值</param> /// <param name="fileInfoEntity">文件信息实体</param> /// <returns></returns> public void SaveForm(string keyValue, FileInfoEntity fileInfoEntity) { try { service.SaveForm(keyValue, fileInfoEntity); } catch (Exception) { throw; } }
/// <summary> /// 上传证件照片 /// </summary> /// <param name="userId"></param> /// <returns></returns> public object UploadCertImages() { try { string res = HttpContext.Current.Request["json"]; dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(res); string id = dy.data.id; string path = itemBll.GetItemValue("imgPath"); FileInfoBLL fileInfoBLL = new FileInfoBLL(); HttpFileCollection files = HttpContext.Current.Request.Files; if (res.Contains("remark")) { string remark = dy.data.remark; deptBll.ExecuteSql(string.Format("delete from base_fileinfo where recid='{0}' and fileid in('{1}')", id, remark.Replace(",", "','"))); } for (int i = 0; i < files.AllKeys.Length; i++) { HttpPostedFile file = files[i]; //获取文件完整文件名(包含绝对路径) //文件存放路径格式:/Resource/ResourceFile/{userId}{data}/{guid}.{后缀名} string fileGuid = Guid.NewGuid().ToString(); long filesize = file.ContentLength; string FileEextension = Path.GetExtension(file.FileName); string uploadDate = DateTime.Now.ToString("yyyyMMdd"); string virtualPath = string.Format("~/Resource/cert/{0}/{1}{2}", uploadDate, fileGuid, FileEextension); string virtualPath1 = string.Format("\\Resource/cert\\{0}\\{1}{2}", uploadDate, fileGuid, FileEextension); string fullFileName = path + virtualPath1; //创建文件夹 string path1 = Path.GetDirectoryName(fullFileName); Directory.CreateDirectory(path1); FileInfoEntity fileInfoEntity = new FileInfoEntity(); if (!System.IO.File.Exists(fullFileName)) { //保存文件 file.SaveAs(fullFileName); } //文件信息写入数据库 fileInfoEntity.FileId = fileGuid; fileInfoEntity.RecId = id; //关联ID fileInfoEntity.FolderId = "cert"; fileInfoEntity.FileName = file.FileName; fileInfoEntity.FilePath = virtualPath; fileInfoEntity.FileSize = filesize.ToString(); fileInfoEntity.FileExtensions = FileEextension; fileInfoEntity.FileType = FileEextension.Replace(".", ""); fileInfoBLL.SaveForm("", fileInfoEntity); } return(new { code = 0, info = "操作成功", data = id }); } catch (Exception ex) { return(new { code = 1, info = ex.Message }); } }
public ActionResult GetFiles(string fileIdlist) { if (!string.IsNullOrEmpty(fileIdlist) && fileIdlist != "undefined") { FileInfoEntity entity = fileInfoBLL.GetEntity(fileIdlist); //return Content(entity.ToJson()); string json = "[{\"FileId\":\"" + entity.FileId + "\",\"FileType\":\"" + entity.FileType + "\",\"FileName\":\"" + entity.FileName + "\"}]"; return(Content(json)); } return(Content("[]")); }
public void SaveForm(FileInfoEntity fileInfoEntity) { try { service.Save(fileInfoEntity); } catch (Exception) { throw; } }
public ActionResult RemoveFile(string fileName, string recId) { FileInfoBLL fileBll = new FileInfoBLL(); FileInfoEntity entity = fileBll.GetEntity(recId, fileName); int res = 0; if (entity != null) { res = fileBll.DeleteFile(recId, fileName, Server.MapPath(entity.FilePath)); } return(res > 0 ? Success("操作成功。") : Error("操作失败")); }