private void fileUpload_FileOk(object sender, CancelEventArgs e) { string FileName = string.Empty; string FullName = string.Empty; string dropbox = Path.GetTempPath(); OpenFileDialog oFileDialog = sender as OpenFileDialog; switch (oFileDialog.DialogResult) { case DialogResult.OK: for (int i = 0; i < oFileDialog.Files.Count; i++) { HttpPostedFileHandle file = oFileDialog.Files[i] as HttpPostedFileHandle; if (file.ContentLength > 0) { FileName = Path.GetFileName(file.PostedFileName); FullName = Path.Combine(dropbox, FileName); file.SaveAs(FullName); txtFileName.Text = FileName; _UploadedFiles.Add(FullName); } } //BindFileExplorer(); this.Update(); break; } }
/// <summary> /// Return uploaded file name /// </summary> /// <param name="objFileDialog"></param> /// <returns></returns> public static string UploadFile(OpenFileDialog objFileDialog, string uploadedPath) { string FileName = string.Empty; string FullName = string.Empty; if (!Directory.Exists(uploadedPath)) { Directory.CreateDirectory(uploadedPath); } if (objFileDialog != null) { for (int i = 0; i < objFileDialog.Files.Count; i++) { HttpPostedFileHandle file = objFileDialog.Files[i] as HttpPostedFileHandle; if (file.ContentLength > 0) { FileName = Path.GetFileName(file.PostedFileName); FullName = Path.Combine(uploadedPath, FileName); file.SaveAs(FullName); } } } return(FileName); }
/// <summary> /// 更新文件——赵英武 /// </summary> /// <param name="user"></param> /// <param name="resId"></param> /// <param name="objFileDialog"></param> public virtual void Update(CUserEntity user, int resId, OpenFileDialog objFileDialog) { CACLEntity acl = new CACLEntity(user.ConnString); acl.Acl_Resource = resId; acl.Acl_Operation = (int)ACLOPERATION.WRITE; if (!user.CheckPrivilege(acl)) { throw new Exception("没有写权限!"); } String filePath; HttpPostedFileHandle hfh = (HttpPostedFileHandle)objFileDialog.Files[0]; CResourceEntity res = new CResourceEntity().Load(resId); user.UpdateFile(resId, hfh.PostedFileName, out filePath); hfh.SaveAs(filePath); }
public virtual void UploadFile(CUserEntity user, int parentResource, OpenFileDialog objFileDialog) { CACLEntity acl = new CACLEntity(user.ConnString); acl.Acl_Resource = parentResource; acl.Acl_Operation = (int)ACLOPERATION.WRITE; if (!user.CheckPrivilege(acl)) { throw new Exception("没有写权限!"); } for (int i = 0; i < objFileDialog.Files.Count; i++) { String filePath; HttpPostedFileHandle hfh = (HttpPostedFileHandle)objFileDialog.Files[i];; user.CreateFile(parentResource, hfh.PostedFileName, out filePath); hfh.SaveAs(filePath); } }