/// <summary> /// 获取并上传附件 /// </summary> public void UpFileData() { string strNewAttachIds = string.Empty; string dataField = Request.Form["dataField"]; string instanceID = Request.Form["InstanceID"] + string.Empty; //新加的属性,待确认 //ERROR: string schemaCode = Request.Form["SchemaCode"] + string.Empty; string bizObjectID = Request.Form["BizObjectID"] + string.Empty; //string workflowPackage = Request.Form["WorkflowPackage"] + string.Empty; //string workflowName = Request.Form["WorkflowName"] + string.Empty; if (dataField == string.Empty) { return; } System.Web.HttpPostedFile theFile; //说明:若控件的参数 <PARAM NAME="DelFileField" VALUE="DELETE_FILE_NAMES"> //则,从Request.Form得到的DELETE_FILE_NAMES集合包含了所有需要删除的文件 //也就是客户端修改过的文件名 string[] delFileNames = Request.Form.GetValues("DELETE_FILE_NAMES"); System.Web.HttpFileCollection uploadFiles = Request.Files; try { OThinker.H3.Data.AttachmentHeader[] headers = null; if (instanceID != string.Empty) { headers = OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.QueryAttachment(schemaCode, bizObjectID, dataField, OThinker.Data.BoolMatchValue.True, string.Empty); } // 增加保存附件文件 for (int i = 0; i < uploadFiles.Count; i++) { theFile = uploadFiles[i]; // "EDITFILE"和客户端的BeginSaveToURL的第二个参数一致 if (uploadFiles.GetKey(i).ToUpper() == "EDITFILE") { // 写入FILE数据 string fname = theFile.FileName; int fsize = theFile.ContentLength; string contentType = theFile.ContentType; byte[] buffer = new byte[theFile.ContentLength]; theFile.InputStream.Read(buffer, 0, fsize); OThinker.H3.Data.Attachment attachment = new OThinker.H3.Data.Attachment() { ObjectID = Guid.NewGuid().ToString(), FileName = fname, ContentType = string.Empty, Content = buffer, DataField = HttpUtility.UrlDecode(dataField), CreatedBy = OThinker.Organization.User.AdministratorID, Downloadable = true, BizObjectId = bizObjectID, BizObjectSchemaCode = schemaCode }; strNewAttachIds += attachment.ObjectID + ","; OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.AddAttachment(attachment); } } if (headers != null && delFileNames != null) { foreach (OThinker.H3.Data.AttachmentHeader header in headers) { if (Array.IndexOf <string>(delFileNames, header.FileName) > -1) { OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.RemoveAttachment(OThinker.Organization.User.AdministratorID, schemaCode, header.BizObjectId, header.ObjectID); } } } Response.Write(strNewAttachIds); } catch (Exception err) { OThinker.H3.Controllers.AppUtility.Engine.LogWriter.Write("NTKO Attachment ERROR:" + err.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Files.Count == 0) { Response.End(); } string ID = Request.Form["ID"]; string dataField = Request.Form["dataField"]; string instanceID = Request.Form["InstanceID"] + string.Empty; string download = Request.Form["download"] + string.Empty; string bizObjectID = Request.Form["BizObjectID"] + string.Empty; string schemaCode = Request.Form["SchemaCode"] + string.Empty; string saveType = Request.Form["SaveType"] + string.Empty;//判断是保存正文还是PDF,doc:正文,pdf:PDF //string workflowPackage = Request.Form["WorkflowPackage"] + string.Empty; //string workflowName = Request.Form["WorkflowName"] + string.Empty; string fileExtension = ".doc"; if (saveType.ToLower() == "pdf") { fileExtension = ".pdf"; } //保存 WORD 文档保存的文件名称为 [流程实例名称].doc,如果流程实例名称为空,那么保存为 BizObjectID.doc string fileName = bizObjectID; if (!string.IsNullOrEmpty(instanceID)) { OThinker.H3.Instance.InstanceContext context = AppUtility.Engine.InstanceManager.GetInstanceContext(instanceID); if (context != null) { string InstanceName = context.InstanceName; if (!string.IsNullOrEmpty(InstanceName)) { fileName = InstanceName; } } else { bizObjectID = instanceID; //发起的时候没有BizObjectID,使用InstanceID,在打开时修改BizObjectID } AttachmentHeader[] attachs = AppUtility.Engine.BizObjectManager.QueryAttachment(schemaCode, bizObjectID, dataField, OThinker.Data.BoolMatchValue.True, null); if (attachs != null && attachs.Length > 0) { ID = attachs[0].AttachmentID; } else { ID = Guid.NewGuid().ToString(); } } else { ID = Guid.NewGuid().ToString(); } fileName = fileName + fileExtension; byte[] fileValue = new byte[Request.Files[0].ContentLength]; if (fileValue.Length == 0) { return; // 没有接收到数据,则不做保存 } Request.Files[0].InputStream.Read(fileValue, 0, Request.Files[0].ContentLength); OThinker.H3.Data.Attachment attachment = new OThinker.H3.Data.Attachment() { ObjectID = ID, FileName = fileName,//HttpUtility.UrlDecode(Request.Files[0].FileName), ContentType = Request.Files[0].ContentType, Content = fileValue, DataField = HttpUtility.UrlDecode(dataField), CreatedBy = this.UserValidator.UserID, Downloadable = true, BizObjectId = bizObjectID, BizObjectSchemaCode = schemaCode }; try { //保存 更新文件 this.Engine.BizObjectManager.RemoveAttachment(string.Empty, schemaCode, attachment.BizObjectId, attachment.AttachmentID); this.Engine.BizObjectManager.AddAttachment(attachment); } catch (Exception ex) { this.Engine.LogWriter.Write("WordSave Error:" + ex.ToString()); } }