// CustomRouterResult ICustomRouter.OnSubmitFile( // public CustomRouterResult OnSubmitFile( /// <summary> /// The on submit file. /// </summary> /// <param name="contentOrganizerWeb">The content organizer web.</param> /// <param name="recordSeries">The record series.</param> /// <param name="userName">The user name.</param> /// <param name="fileContent">The file content.</param> /// <param name="properties">The properties.</param> /// <param name="finalFolder">The final folder.</param> /// <param name="resultDetails">The result details.</param> /// <returns> /// The Microsoft.Office.RecordsManagement.RecordsRepository.CustomRouterResult. /// </returns> public CustomRouterResult OnSubmitFile( EcmDocumentRoutingWeb contentOrganizerWeb, string recordSeries, string userName, Stream fileContent, RecordsRepositoryProperty[] properties, SPFolder finalFolder, ref string resultDetails) { if (contentOrganizerWeb == null) { throw new ArgumentNullException("contentOrganizerWeb"); } // We should have a Content Organizer enabled web if (!contentOrganizerWeb.IsRoutingEnabled) { throw new ArgumentException("Invalid content organizer."); } if (String.IsNullOrEmpty(recordSeries)) { throw new ArgumentNullException("recordSeries"); } if (String.IsNullOrEmpty(userName)) { throw new ArgumentNullException("userName"); } if (fileContent.Length == 0) { throw new ArgumentNullException("fileContent"); } if (properties == null) { throw new ArgumentNullException("properties"); } if (!finalFolder.Exists) { throw new ArgumentNullException("finalFolder"); } UnifiedLoggingServer.LogMedium("---- CR.OnSubmitFile() 7@"); UnifiedLoggingServer.LogMedium("-@1:" + contentOrganizerWeb.GetType()); UnifiedLoggingServer.LogMedium("-@2:" + recordSeries); UnifiedLoggingServer.LogMedium("-@3:" + userName); UnifiedLoggingServer.LogMedium("-@4:" + fileContent.Length); UnifiedLoggingServer.LogMedium("-@5:" + properties.Length); UnifiedLoggingServer.LogMedium("-@6:" + finalFolder.Name); UnifiedLoggingServer.LogMedium("-@7:" + resultDetails); try { foreach (RecordsRepositoryProperty recordsRepositoryProperty in properties) { string s = "---- CR.Props [" + recordsRepositoryProperty.Name + "|" + recordsRepositoryProperty.Value + "]"; this.log += s + "\n"; UnifiedLoggingServer.LogMedium(s); } // Create a Hashtable of properties which forms the metadata for the file Hashtable fileProperties = EcmDocumentRouter.GetHashtableForRecordsRepositoryProperties(properties, recordSeries); UnifiedLoggingServer.LogMedium("---- CR.OnSubmitFile().GetHashtableForRecordsRepositoryProperties:" + fileProperties.Count); resultDetails += this.log; UnifiedLoggingServer.LogMedium("-@FilNm_:" + this.FileName); UnifiedLoggingServer.LogMedium("-@FilPt_:" + this.FilePath); UnifiedLoggingServer.LogMedium("-@SPusr_:" + this.SpUser); // Save it to disk EcmDocumentRouter.SaveFileToFinalLocation( contentOrganizerWeb, finalFolder, fileContent, this.FileName, this.FilePath, fileProperties, this.SpUser, true, "CustomRouter CheckInComment"); } catch (Exception e) { UnifiedLoggingServer.LogHigh("---- CR:TryCatch savefiletofinallocation" + e.Message); return(CustomRouterResult.SuccessCancelFurtherProcessing); } return(CustomRouterResult.SuccessContinueProcessing); }
CustomRouterResult ICustomRouter.OnSubmitFile(EcmDocumentRoutingWeb web, string recordSeries, string userName, Stream fileContent, RecordsRepositoryProperty[] properties, SPFolder finalFolder, ref string resultDetails) { CustomRouterResult result = new CustomRouterResult(); try { if (web == null) { throw new ArgumentNullException("web"); } if (!web.IsRoutingEnabled) { throw new ArgumentException("Invalid content organizer."); } string submitterLoginName = Resource.DefaultAdminAccount; string submittingUserName = userName; if (string.IsNullOrEmpty(userName)) { submittingUserName = submitterLoginName; } using (SPSite site = new SPSite(web.DropOffZoneUrl)) { using (SPWeb rootWeb = site.OpenWeb()) { SPUser submittingUser = rootWeb.SiteUsers[submittingUserName]; Hashtable fileProperties = EcmDocumentRouter.GetHashtableForRecordsRepositoryProperties(properties, recordSeries); fileProperties["Title"] = fileProperties["Name"]; string modifiedFileName = fileProperties["BaseName"] + " - " + fileProperties["Work_x0020_Matter"] + "." + fileProperties["File Type"]; // Check for an existing file, grab the existing document ID if it exists SPFile existingFile = rootWeb.GetFile(finalFolder.ServerRelativeUrl + "/" + modifiedFileName); if (existingFile.Exists) { if ((existingFile.Item.Fields.ContainsField("Work_x0020_Matter_x0020_Document_x003a__x0020_Status") && existingFile.Item["Work_x0020_Matter_x0020_Document_x003a__x0020_Status"].ToString() == "Final") || Records.IsRecord(existingFile.Item)) { result = CustomRouterResult.SuccessCancelFurtherProcessing; resultDetails = "There was an error processing this document. It has already been added to the specified work matter and has been marked as final. The file cannot be overwritten."; SPUtility.TransferToErrorPage(resultDetails); return(result); } fileProperties[Resource.FieldDocumentIDString] = existingFile.Item[Resource.FieldDocumentIDString]; } SPFile newFile = EcmDocumentRouter.SaveFileToFinalLocation(web, finalFolder, fileContent, modifiedFileName, "", fileProperties, submittingUser, false, ""); SPListItem newItem = newFile.Item; if (newFile.Name != modifiedFileName) { result = CustomRouterResult.SuccessCancelFurtherProcessing; resultDetails = "There was an error processing this document. It has already been added to the specified work matter and has been marked as final. The file cannot be overwritten."; // We shouldn't delete these things. Some documents are being deleted unnecessarily //using (DisabledEventsScope scope = new DisabledEventsScope()) //{ // newItem.Delete(); //} SPUtility.TransferToErrorPage(resultDetails); return(result); } newItem["Modified"] = DateTime.Now; newItem.UpdateOverwriteVersion(); result = CustomRouterResult.SuccessCancelFurtherProcessing; } } } catch (Exception ex) { Util.LogError("OnSubmitFile failed with message: " + ex.Message); } result = CustomRouterResult.SuccessCancelFurtherProcessing; return(result); }