private void UploadFile(long PostilID) { string FileName = ""; HtmlForm FrmCompose = (HtmlForm)this.Page.FindControl("PostilDocument"); //生成附件目录 if (!System.IO.Directory.Exists(Server.MapPath(".") + "\\AttachFiles")) { System.IO.Directory.CreateDirectory(Server.MapPath(".") + "\\AttachFiles"); } try { HtmlInputFile hif = ((HtmlInputFile)(FrmCompose.FindControl("fileTemplate"))); if (hif.PostedFile != null) { if (hif.PostedFile.FileName.Trim() != "") { FileName = System.IO.Path.GetFileName(hif.PostedFile.FileName); //生成用户目录 if (!System.IO.Directory.Exists(Server.MapPath(".") + "\\AttachFiles\\" + UserName)) { System.IO.Directory.CreateDirectory(Server.MapPath(".") + "\\AttachFiles\\" + UserName); } Random TempNameInt = new Random(); string NewDocDirName = TempNameInt.Next(100000000).ToString(); //生成随机目录 if (!System.IO.Directory.Exists(Server.MapPath(".") + "\\AttachFiles\\" + UserName + "\\" + NewDocDirName)) { System.IO.Directory.CreateDirectory(Server.MapPath(".") + "\\AttachFiles\\" + UserName + "\\" + NewDocDirName); } TempNameInt = null; //保存文件 hif.PostedFile.SaveAs(Server.MapPath(".") + "\\AttachFiles\\" + UserName + "\\" + NewDocDirName + "\\" + FileName); UDS.Components.DocAttachFile att = new UDS.Components.DocAttachFile(); UDS.Components.DocumentFlow df = new UDS.Components.DocumentFlow(); // 初始化 att.FileAttribute = 0; att.FileSize = hif.PostedFile.ContentLength; att.FileName = FileName; att.FileAuthor = UserName; att.FileCatlog = "公文"; att.FileVisualPath = "\\AttachFiles\\" + UserName + "\\" + NewDocDirName + "\\"; att.FileAddedDate = DateTime.Now.ToString();; df.AddPostilAttach(att, PostilID); df = null; att = null; } hif = null; } } catch (Exception ex) { UDS.Components.Error.Log(ex.ToString()); } finally { } }
private void UploadFile(long PostilID) { string FileName = ""; HtmlForm FrmCompose = (HtmlForm)this.Page.FindControl("PostilDocument"); //���ɸ���Ŀ¼ if(!System.IO.Directory.Exists(Server.MapPath(".")+"\\AttachFiles")) { System.IO.Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles"); } try { HtmlInputFile hif = ((HtmlInputFile)(FrmCompose.FindControl("fileTemplate"))); if(hif.PostedFile!=null) { if(hif.PostedFile.FileName.Trim()!="") { FileName = System.IO.Path.GetFileName(hif.PostedFile.FileName); //�����û�Ŀ¼ if(!System.IO.Directory.Exists(Server.MapPath(".")+"\\AttachFiles\\" + UserName)) { System.IO.Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\"+ UserName); } Random TempNameInt = new Random(); string NewDocDirName = TempNameInt.Next(100000000).ToString(); //�������Ŀ¼ if(!System.IO.Directory.Exists(Server.MapPath(".")+"\\AttachFiles\\" + UserName + "\\" + NewDocDirName)) { System.IO.Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\" + UserName + "\\" + NewDocDirName); } TempNameInt = null; //�����ļ� hif.PostedFile.SaveAs(Server.MapPath(".")+"\\AttachFiles\\" + UserName + "\\" + NewDocDirName + "\\" + FileName); UDS.Components.DocAttachFile att = new UDS.Components.DocAttachFile(); UDS.Components.DocumentFlow df = new UDS.Components.DocumentFlow(); // ��ʼ�� att.FileAttribute = 0; att.FileSize = hif.PostedFile.ContentLength; att.FileName = FileName; att.FileAuthor = UserName; att.FileCatlog = "����"; att.FileVisualPath = "\\AttachFiles\\" + UserName + "\\" + NewDocDirName + "\\"; att.FileAddedDate = DateTime.Now.ToString();; df.AddPostilAttach(att,PostilID); df = null; att = null; } hif=null; } } catch(Exception ex) { UDS.Components.Error.Log(ex.ToString()); } finally { } }