/// <summary> /// Fetches the properties. /// </summary> /// <param name="spFieldCollection">The SP field collection.</param> /// <param name="listItem">The list item.</param> /// <returns> /// The Microsoft.SharePoint.RecordsRepositoryProperty[]. /// </returns> private RecordsRepositoryProperty[] FetchProperties(SPFieldCollection spFieldCollection, SPListItem listItem) { // create a property list/ array for each metadata field List <RecordsRepositoryProperty> propertyList = new List <RecordsRepositoryProperty>(); foreach (SPField spField in spFieldCollection) { try { string value = Convert.ToString(spField.GetFieldValue(Convert.ToString(listItem[spField.Title]))); UnifiedLoggingServer.LogMedium("---- CRR_Props[" + spField.Title + "_|_" + spField.TypeAsString + "_|_" + value + "]"); RecordsRepositoryProperty property = new RecordsRepositoryProperty { Name = spField.Title, Type = spField.TypeAsString, Value = value }; propertyList.Add(property); } catch (Exception e) { } } return(propertyList.ToArray()); }
/// <summary> /// OnSubmitFile method for the content organizer /// </summary> /// <param name="contentOrganizerWeb">The web.</param> /// <param name="recordSeries">Record series.</param> /// <param name="userName">Submitting user name.</param> /// <param name="fileContent">File content.</param> /// <param name="properties">File properties.</param> /// <param name="finalFolder">The final folder.</param> /// <param name="resultDetails">Result processing details.</param> /// <returns>The CustomRouterResult.</returns> public override CustomRouterResult OnSubmitFile(EcmDocumentRoutingWeb contentOrganizerWeb, string recordSeries, string userName, Stream fileContent, RecordsRepositoryProperty[] properties, SPFolder finalFolder, ref string resultDetails) { this.ResolveDependencies(); var web = new SPSite(contentOrganizerWeb.DropOffZoneUrl).OpenWeb(); // Get routed document properties var documentProperties = EcmDocumentRouter.GetHashtableForRecordsRepositoryProperties( properties, recordSeries); // Example: Get a conventional field (8553196d-ec8d-4564-9861-3dbe931050c8 = FileLeafRef) string originalFileName = documentProperties["8553196d-ec8d-4564-9861-3dbe931050c8"].ToString(); // EncodedAbsUrl field string originalFileUrl = documentProperties["7177cfc7-f399-4d4d-905d-37dd51bc90bf"].ToString(); // Example: Get the SharePoint user who perform the action var user = web.EnsureUser(userName); // Example: Deal with errors if (originalFileName.ToLower().Contains("error")) { // Display error message SPUtility.TransferToErrorPage( string.Format(CultureInfo.InvariantCulture, "This is an error message")); // Save the error file in the Drop Off Library this.SaveDocumentToDropOffLibrary( fileContent, documentProperties, contentOrganizerWeb.DropOffZone, originalFileName, contentOrganizerWeb, user); return CustomRouterResult.SuccessCancelFurtherProcessing; } // Here is the business logic // Example: get a taxonomy field from document properties string confidentialityTaxValue = documentProperties[MyFields.MyTaxField.InternalName].ToString(); string confidentiality = new TaxonomyFieldValue(confidentialityTaxValue).Label; // Example: Set a new field to the item var indexDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime( DateHelper.GetSharePointDateUtc(web, DateTime.Now)); // Be careful, if you want to add or modify some properties, use internal GUID instead of InternalName if (!documentProperties.ContainsKey(MyFields.MyIndexDate.ID.ToString())) { documentProperties.Add(MyFields.MyIndexDate.ID.ToString(), indexDate); } else { documentProperties[MyFields.MyIndexDate.ID.ToString()] = indexDate; } // Save the file in the final destination. You can get the newly created file here and apply further actions. var file = EcmDocumentRouter.SaveFileToFinalLocation( contentOrganizerWeb, finalFolder, fileContent, originalFileName, originalFileUrl, documentProperties, user, true, string.Empty); web.Dispose(); return CustomRouterResult.SuccessContinueProcessing; }
/// <summary> /// OnSubmitFile method for the content organizer /// </summary> /// <param name="contentOrganizerWeb">The web.</param> /// <param name="recordSeries">Record series.</param> /// <param name="userName">Submitting user name.</param> /// <param name="fileContent">File content.</param> /// <param name="properties">File properties.</param> /// <param name="finalFolder">The final folder.</param> /// <param name="resultDetails">Result processing details.</param> /// <returns>The CustomRouterResult.</returns> public abstract CustomRouterResult OnSubmitFile(EcmDocumentRoutingWeb contentOrganizerWeb, string recordSeries, string userName, Stream fileContent, RecordsRepositoryProperty[] properties, SPFolder finalFolder, ref string resultDetails);