private void objFile_FileOk(object sender, CancelEventArgs e) { int selectedResource = GetSelectedTreeResource(); if (selectedResource <= 0) { MessageBox.Show("请选择一个目录", "文档管理系统", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { OpenFileDialog objFileDialog = (OpenFileDialog)sender; for (int i = 0; i < objFileDialog.Files.Count; i++) { String filePath; HttpPostedFileHandle hfh = (HttpPostedFileHandle)objFileDialog.Files[i];; _currentUser.CreateFile(selectedResource, hfh.PostedFileName, out filePath); hfh.SaveAs(filePath); DirTree selTree = GetActiveTree(); selTree.ReloadFileList(); } } catch (Exception ex) { MessageBox.Show("创建文件失败:" + ex.Message, "文档管理系统", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Loads the thumbs. /// </summary> /// <param name="objHttpContext">The HTTP context.</param> /// <param name="intFileIndex">The current file index.</param> /// <returns></returns> private HttpPostedFileHandle[] LoadThumbs(HostContext objHttpContext, int intFileIndex) { // List of posted tumbnails List <HttpPostedFileHandle> objThumbnails = new List <HttpPostedFileHandle>(); int intThumbIndex = 1; // Reference to the posted tumbnail HostPostedFile objPostedThumb = null; do { // Get the posted thumbnail objPostedThumb = objHttpContext.Request.Files[string.Format("Thumbnail{0}_{1}", intThumbIndex, intFileIndex)]; if (objPostedThumb != null) { // Get the visual webgui upload file objThumbnails.Add(HttpPostedFileHandle.Create(objPostedThumb)); } intThumbIndex++; }while (objPostedThumb != null); return(objThumbnails.ToArray()); }
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> /// Initializes a new instance of the <see cref="ImageUploaderFile"/> class. /// </summary> /// <param name="objHttpContext">The obj HTTP context.</param> /// <param name="intFileIndex">Index of the int file.</param> internal ImageUploaderFile(HostContext objHttpContext, int intFileIndex) { // Load from request mobjThumbs = LoadThumbs(objHttpContext, intFileIndex); mobjFile = LoadFile(objHttpContext, intFileIndex); mstrDescription = LoadDescription(objHttpContext, intFileIndex); }
/// <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> /// Loads the file. /// </summary> /// <param name="objHttpContext">The HTTP context.</param> /// <param name="intFileIndex">The current file index.</param> /// <returns></returns> private HttpPostedFileHandle LoadFile(HostContext objHttpContext, int intFileIndex) { HttpPostedFileHandle objFile = null; HostPostedFile objPostedFile = objHttpContext.Request.Files[string.Format("SourceFile_{0}", intFileIndex)]; if (objPostedFile != null) { objFile = HttpPostedFileHandle.Create(objPostedFile); } return(objFile); }
/// <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); } }