private void MapObject(SPOfficialFileHost currentObject, OfficialFileHostDefinition typedDefinition) { currentObject.OfficialFileUrl = new Uri(typedDefinition.OfficialFileUrl); currentObject.OfficialFileName = typedDefinition.OfficialFileName; currentObject.ShowOnSendToMenu = typedDefinition.ShowOnSendToMenu; if (!string.IsNullOrEmpty(typedDefinition.Explanation)) { currentObject.Explanation = typedDefinition.Explanation; } currentObject.Action = (SPOfficialFileAction)typedDefinition.Action; }
/// <summary> /// Submit all selected items to the SharePoint Content Organizer /// Note that user must have EditListItems and DeleteListItem to reindex a document. /// </summary> private void IndexItems(SPWeb web) { // Get Query String Parameters var listUrlDir = web.Url + "/" + this.Request.QueryString["ListUrlDir"]; var siteUrl = this.Request.QueryString["SiteUrl"]; var items = this.Request["Items"] != null ? this.Request["Items"].Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; // Allow unsafe updates to edit the curretn list items web.AllowUnsafeUpdates = true; // Ge the target list var list = web.GetList(listUrlDir); var host = new SPOfficialFileHost { OfficialFileUrl = new Uri(web.Url + "/_vti_bin/OfficialFile.asmx"), OfficialFileName = "Content Organizer Automatic Indexation", Action = SPOfficialFileAction.Move }; string result; var processedItems = new Collection<string>(); foreach (string id in items) { // If the item has not already been processed if (!processedItems.Contains(id)) { // Fetch list item var listItem = list.GetItemById(int.Parse(id, CultureInfo.InvariantCulture)); // Check if the document exist before send (Maybe already routed to the Drop Off Libray through an other selected item) if (listItem != null) { string fileType = listItem.ContentType.Name; // Send the document to the Content Organizer listItem.File.SendToOfficialFile(fileType, host, null, SPOfficialFileSubmissionMode.None, out result); } } } web.AllowUnsafeUpdates = false; }
private SPOfficialFileHost CreateNewObject(SPWebApplication webApp, OfficialFileHostDefinition typedDefinition) { SPOfficialFileHost result = null; if (typedDefinition.CreateUniqueId) { result = new SPOfficialFileHost(true); } else { result = new SPOfficialFileHost(false); } webApp.OfficialFileHosts.Add(result); return(result); }