public static void ShareToFtp() { string flowNo = HttpContext.Current.Request.QueryString["FK_Flow"]; string bbsNo = HttpContext.Current.Request.QueryString["BBS"]; string sharTo = HttpContext.Current.Request.QueryString["ShareTo"]; Flow flow = new Flow(flowNo); string ip = "online.ccflow.org"; string userNo = "ccflowlover"; string pass = "******"; try { FtpSupport.FtpConnection conn = new FtpSupport.FtpConnection(ip, userNo, pass); //conn.SetCurrentDirectory("/"); conn.SetCurrentDirectory(FlowTemplate + "\\" + sharTo + "\\"); string createDir = bbsNo + "." + flow.No + "." + flow.Name; if (!conn.DirectoryExist(createDir)) { conn.CreateDirectory(createDir); } conn.SetCurrentDirectory(createDir + "\\"); HttpContext.Current.Response.ContentType = "text/plain"; string dir = BP.Sys.SystemConfig.PathOfDataUser + @"\FlowDesc\" + flow.No + "." + flow.Name + "\\"; if (System.IO.Directory.Exists(dir)) { string[] fls = System.IO.Directory.GetFiles(dir); foreach (string fff in fls) { string fileName = fff.Substring(fff.LastIndexOf("\\") + 1); if (fileName.Contains("@"))// 历史数据不上传 { continue; } conn.PutFile(fff, fileName); //conn.DeleteFile(fileName); } //上传成功 HttpContext.Current.Response.Write("上传成功"); } else { HttpContext.Current.Response.Write("该流程暂没有可发布文件"); } conn.Close(); } catch (Exception e) { HttpContext.Current.Response.Write("流程模板发布失败:" + e.Message); } }
//多附件上传方法 public void MoreAttach() { string PKVal = this.GetRequestVal("PKVal"); string attachPk = this.GetRequestVal("AttachPK"); // 多附件描述. BP.Sys.FrmAttachment athDesc = new BP.Sys.FrmAttachment(attachPk); MapData mapData = new MapData(athDesc.FK_MapData); string msg = null; GEEntity en = new GEEntity(athDesc.FK_MapData); en.PKVal = PKVal; en.Retrieve(); for (int i = 0; i < context.Request.Files.Count; i++) { HttpPostedFile file = context.Request.Files[i]; #region 文件上传的iis服务器上 or db数据库里. if (athDesc.AthSaveWay == AthSaveWay.IISServer) { string savePath = athDesc.SaveTo; if (savePath.Contains("@") == true || savePath.Contains("*") == true) { /*如果有变量*/ savePath = savePath.Replace("*", "@"); savePath = BP.WF.Glo.DealExp(savePath, en, null); if (savePath.Contains("@") && this.FK_Node != 0) { /*如果包含 @ */ BP.WF.Flow flow = new BP.WF.Flow(this.FK_Flow); BP.WF.Data.GERpt myen = flow.HisGERpt; myen.OID = this.WorkID; myen.RetrieveFromDBSources(); savePath = BP.WF.Glo.DealExp(savePath, myen, null); } if (savePath.Contains("@") == true) { throw new Exception("@路径配置错误,变量没有被正确的替换下来." + savePath); } } else { savePath = athDesc.SaveTo + "\\" + PKVal; } //替换关键的字串. savePath = savePath.Replace("\\\\", "\\"); try { savePath = context.Server.MapPath("~/" + savePath); } catch (Exception) { } try { if (System.IO.Directory.Exists(savePath) == false) { System.IO.Directory.CreateDirectory(savePath); } } catch (Exception ex) { throw new Exception("@创建路径出现错误,可能是没有权限或者路径配置有问题:" + context.Server.MapPath("~/" + savePath) + "===" + savePath + "@技术问题:" + ex.Message); } string exts = System.IO.Path.GetExtension(file.FileName).ToLower().Replace(".", ""); string guid = BP.DA.DBAccess.GenerGUID(); string fileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); if (fileName.LastIndexOf("\\") > 0) { fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1); } string ext = System.IO.Path.GetExtension(file.FileName); string realSaveTo = savePath + "\\" + guid + "." + fileName + ext; realSaveTo = realSaveTo.Replace("~", "-"); realSaveTo = realSaveTo.Replace("'", "-"); realSaveTo = realSaveTo.Replace("*", "-"); file.SaveAs(realSaveTo); //执行附件上传前事件,added by liuxc,2017-7-15 msg = mapData.DoEvent(FrmEventList.AthUploadeBefore, en, "@FK_FrmAttachment=" + athDesc.MyPK + "@FileFullName=" + realSaveTo); if (!string.IsNullOrEmpty(msg)) { BP.Sys.Glo.WriteLineError("@AthUploadeBefore事件返回信息,文件:" + file.FileName + "," + msg); try { File.Delete(realSaveTo); } catch { } //note:此处如何向前uploadify传递失败信息,有待研究 //this.Alert("上传附件错误:" + msg, true); return; } FileInfo info = new FileInfo(realSaveTo); FrmAttachmentDB dbUpload = new FrmAttachmentDB(); dbUpload.MyPK = guid; // athDesc.FK_MapData + oid.ToString(); dbUpload.NodeID = this.FK_Node.ToString(); dbUpload.FK_FrmAttachment = attachPk; dbUpload.FK_MapData = athDesc.FK_MapData; dbUpload.FK_FrmAttachment = attachPk; dbUpload.FileExts = info.Extension; #region 处理文件路径,如果是保存到数据库,就存储pk. if (athDesc.AthSaveWay == AthSaveWay.IISServer) { //文件方式保存 dbUpload.FileFullName = realSaveTo; } if (athDesc.AthSaveWay == AthSaveWay.FTPServer) { //保存到数据库 dbUpload.FileFullName = dbUpload.MyPK; } #endregion 处理文件路径,如果是保存到数据库,就存储pk. dbUpload.FileName = fileName + ext; dbUpload.FileSize = (float)info.Length; dbUpload.RDT = DataType.CurrentDataTimess; dbUpload.Rec = BP.Web.WebUser.No; dbUpload.RecName = BP.Web.WebUser.Name; dbUpload.RefPKVal = PKVal; dbUpload.FID = this.FID; //if (athDesc.IsNote) // dbUpload.MyNote = this.Pub1.GetTextBoxByID("TB_Note").Text; //if (athDesc.Sort.Contains(",")) // dbUpload.Sort = this.Pub1.GetDDLByID("ddl").SelectedItemStringVal; dbUpload.UploadGUID = guid; dbUpload.Insert(); if (athDesc.AthSaveWay == AthSaveWay.DB) { //执行文件保存. BP.DA.DBAccess.SaveFileToDB(realSaveTo, dbUpload.EnMap.PhysicsTable, "MyPK", dbUpload.MyPK, "FDB"); } //执行附件上传后事件,added by liuxc,2017-7-15 msg = mapData.DoEvent(FrmEventList.AthUploadeAfter, en, "@FK_FrmAttachment=" + dbUpload.FK_FrmAttachment + "@FK_FrmAttachmentDB=" + dbUpload.MyPK + "@FileFullName=" + dbUpload.FileFullName); if (!string.IsNullOrEmpty(msg)) { BP.Sys.Glo.WriteLineError("@AthUploadeAfter事件返回信息,文件:" + dbUpload.FileName + "," + msg); } } #endregion 文件上传的iis服务器上 or db数据库里. #region 保存到数据库 / FTP服务器上. if (athDesc.AthSaveWay == AthSaveWay.DB || athDesc.AthSaveWay == AthSaveWay.FTPServer) { string guid = DBAccess.GenerGUID(); //把文件临时保存到一个位置. string temp = SystemConfig.PathOfTemp + "" + guid + ".tmp"; try { file.SaveAs(temp); } catch (Exception ex) { System.IO.File.Delete(temp); file.SaveAs(temp); } // fu.SaveAs(temp); //执行附件上传前事件,added by liuxc,2017-7-15 msg = mapData.DoEvent(FrmEventList.AthUploadeBefore, en, "@FK_FrmAttachment=" + athDesc.MyPK + "@FileFullName=" + temp); if (string.IsNullOrEmpty(msg) == false) { BP.Sys.Glo.WriteLineError("@AthUploadeBefore事件返回信息,文件:" + file.FileName + "," + msg); try { File.Delete(temp); } catch { } throw new Exception("err@上传附件错误:" + msg); } FileInfo info = new FileInfo(temp); FrmAttachmentDB dbUpload = new FrmAttachmentDB(); dbUpload.MyPK = BP.DA.DBAccess.GenerGUID(); dbUpload.NodeID = FK_Node.ToString(); dbUpload.FK_FrmAttachment = athDesc.MyPK; dbUpload.FID = this.FID; //流程id. if (athDesc.AthUploadWay == AthUploadWay.Inherit) { /*如果是继承,就让他保持本地的PK. */ dbUpload.RefPKVal = PKVal.ToString(); } if (athDesc.AthUploadWay == AthUploadWay.Interwork) { /*如果是协同,就让他是PWorkID. */ Paras ps = new Paras(); ps.SQL = "SELECT PWorkID FROM WF_GenerWorkFlow WHERE WorkID=" + SystemConfig.AppCenterDBVarStr + "WorkID"; ps.Add("WorkID", PKVal); string pWorkID = BP.DA.DBAccess.RunSQLReturnValInt(ps, 0).ToString(); if (pWorkID == null || pWorkID == "0") { pWorkID = PKVal; } dbUpload.RefPKVal = pWorkID; } dbUpload.FK_MapData = athDesc.FK_MapData; dbUpload.FK_FrmAttachment = athDesc.MyPK; dbUpload.FileName = file.FileName; dbUpload.FileSize = (float)info.Length; dbUpload.RDT = DataType.CurrentDataTimess; dbUpload.Rec = BP.Web.WebUser.No; dbUpload.RecName = BP.Web.WebUser.Name; //if (athDesc.IsNote) // dbUpload.MyNote = this.Pub1.GetTextBoxByID("TB_Note").Text; //if (athDesc.Sort.Contains(",")) //{ // string[] strs = athDesc.Sort.Contains("@") == true ? athDesc.Sort.Substring(athDesc.Sort.LastIndexOf("@") + 1).Split(',') : athDesc.Sort.Split(','); // BP.Web.Controls.DDL ddl = this.Pub1.GetDDLByID("ddl"); // dbUpload.Sort = strs[0]; // if (ddl != null) // { // int selectedIndex = string.IsNullOrEmpty(ddl.SelectedItemStringVal) ? 0 : int.Parse(ddl.SelectedItemStringVal); // dbUpload.Sort = strs[selectedIndex]; // } //} dbUpload.UploadGUID = guid; if (athDesc.AthSaveWay == AthSaveWay.DB) { dbUpload.Insert(); //把文件保存到指定的字段里. dbUpload.SaveFileToDB("FileDB", temp); } if (athDesc.AthSaveWay == AthSaveWay.FTPServer) { /*保存到fpt服务器上.*/ FtpSupport.FtpConnection ftpconn = new FtpSupport.FtpConnection(SystemConfig.FTPServerIP, SystemConfig.FTPUserNo, SystemConfig.FTPUserPassword); string ny = DateTime.Now.ToString("yyyy_MM"); //判断目录年月是否存在. if (ftpconn.DirectoryExist(ny) == false) { ftpconn.CreateDirectory(ny); } ftpconn.SetCurrentDirectory(ny); //判断目录是否存在. if (ftpconn.DirectoryExist(athDesc.FK_MapData) == false) { ftpconn.CreateDirectory(athDesc.FK_MapData); } //设置当前目录,为操作的目录。 ftpconn.SetCurrentDirectory(athDesc.FK_MapData); //把文件放上去. ftpconn.PutFile(temp, guid + "." + dbUpload.FileExts); ftpconn.Close(); //设置路径. dbUpload.FileFullName = ny + "//" + athDesc.FK_MapData + "//" + guid + "." + dbUpload.FileExts; dbUpload.Insert(); } //执行附件上传后事件,added by liuxc,2017-7-15 msg = mapData.DoEvent(FrmEventList.AthUploadeAfter, en, "@FK_FrmAttachment=" + dbUpload.FK_FrmAttachment + "@FK_FrmAttachmentDB=" + dbUpload.MyPK + "@FileFullName=" + temp); if (!string.IsNullOrEmpty(msg)) { BP.Sys.Glo.WriteLineError("@AthUploadeAfter事件返回信息,文件:" + dbUpload.FileName + "," + msg); } } #endregion 保存到数据库. } }
public void DoSave() { if (WebUser.FK_Flow == null) { MessageBox.Show("您没有选择流程您不能存盘。"); return; } if (WebUser.WorkID == 0) { //通过模板新的一个公文,创建一个草稿,生成工作ID。 Work wk = new Work(); wk.NodeID = WebUser.FK_Node; wk.Title = "公文" + DateTime.Now.ToString("MM月dd号"); wk.RDT = DateTime.Now.ToString("yyyy-MM-dd hh:mm"); wk.CDT = DateTime.Now.ToString("yyyy-MM-dd hh:mm"); wk.Rec = WebUser.No; wk.FK_Dept = WebUser.FK_Dept; wk.Insert(); WebUser.WorkID = wk.OID; WebUser.HisWork = wk; } else { if (WebUser.IsStartNode == false) { //*判断是否可以执行当前的工作,如果不可以就提示不让保存。 */ //string sql = "SELECT COUNT( a.Workid) FROM dbo.WF_GenerWorkFlow a , dbo.WF_GenerWorkerList b WHERE a.workid=b.workid and a.fk_node=b.fk_node and b.fk_node=" + WebUser.FK_Node + " and b.fk_emp='" + WebUser.No + "' and b.IsEnable=1 and a.workid=" + WebUser.WorkID; //if (DBAccess.RunSQLReturnTable(sql).Rows[0][0].ToString() == "0") //{ // MessageBox.Show("您不能将此文件存储在服务器上。原因如下:\t\n1,此工作已经完成,文件您不能在修改它。\t\n2、当前文件非您创建或者编辑的。", "保存错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return; //} } } #region 把文件放在服务器上 FtpSupport.FtpConnection conn = Glo.HisFtpConn; try { conn.SetCurrentDirectory("/DocFlow/" + WebUser.FK_Flow + "/" + WebUser.WorkID + "/"); } catch { if (conn.DirectoryExist("/DocFlow/") == false) { conn.CreateDirectory("/DocFlow/"); } if (conn.DirectoryExist("/DocFlow/" + WebUser.FK_Flow + "/") == false) { conn.CreateDirectory("/DocFlow/" + WebUser.FK_Flow + "/"); } if (conn.DirectoryExist("/DocFlow/" + WebUser.FK_Flow + "/" + WebUser.WorkID + "/") == false) { conn.CreateDirectory("/DocFlow/" + WebUser.FK_Flow + "/" + WebUser.WorkID); } conn.SetCurrentDirectory("/DocFlow/" + WebUser.FK_Flow + "/" + WebUser.WorkID + "/"); } string file = Glo.PathOfTInstall + DateTime.Now.ToString("MMddhhmmss") + ".doc"; ThisAddIn.SaveAs(file); System.IO.File.Copy(file, "c:\\Tmp.doc", true); conn.PutFile("c:\\Tmp.doc", WebUser.FK_Node + "@" + WebUser.No + ".doc"); conn.PutFile("c:\\Tmp.doc", WebUser.WorkID + ".doc"); conn.Close(); #endregion 把文件放在服务器上 System.IO.File.Delete("c:\\Tmp.doc"); MessageBox.Show("您的文件已经保存到服务器上", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public string FtpMethod(string doType, string v1, string v2, string v3) { try { FtpSupport.FtpConnection conn = new FtpSupport.FtpConnection("192.168.1.138", "administrator", "jiaozi"); switch (doType) { case "ShareFrm": /*共享模板*/ MapData md = new MapData(); DataSet ds = md.GenerHisDataSet(); string file = BP.SystemConfig.PathOfTemp + v1 + "_" + v2 + "_" + DateTime.Now.ToString("MM-dd hh-mm") + ".xml"; ds.WriteXml(file); conn.SetCurrentDirectory("/"); conn.SetCurrentDirectory("/Upload.Form/"); conn.SetCurrentDirectory(v3); conn.PutFile(file, md.Name + ".xml"); conn.Close(); return(null); case "GetDirs": // return "@01.日常办公@02.人力资源@03.其它类"; conn.SetCurrentDirectory(v1); FtpSupport.Win32FindData[] dirs = conn.FindFiles(); conn.Close(); string dirsStr = ""; foreach (FtpSupport.Win32FindData dir in dirs) { dirsStr += "@" + dir.FileName; } return(dirsStr); case "GetFls": conn.SetCurrentDirectory(v1); FtpSupport.Win32FindData[] fls = conn.FindFiles(); conn.Close(); string myfls = ""; foreach (FtpSupport.Win32FindData fl in fls) { myfls += "@" + fl.FileName; } return(myfls); case "LoadTempleteFile": string fileFtpPath = v1; conn.SetCurrentDirectory("/Form.表单模版/"); conn.SetCurrentDirectory(v3); /*下载文件到指定的目录: */ string tempFile = BP.SystemConfig.PathOfTemp + "\\" + v2 + ".xml"; conn.GetFile(v1, tempFile, false, FileAttributes.Archive, FtpSupport.FtpTransferType.Ascii); return(this.LoadFrmTempleteFile(tempFile, v2, true, true)); default: return(null); } } catch (Exception ex) { return("Error:" + ex.Message); } }