private void RecuperarInformacion_ExecuteCode(object sender, EventArgs e) { itemOC = workflowProperties.Item; try { autonomina = this.VerificarAutonomia(); if (autonomina) { #region Aprobar automaticamente el item SPModerationInformation estadoAprobacion = itemOC.ModerationInformation; estadoAprobacion.Status = SPModerationStatusType.Approved; using (DisabledItemEventsScope scope = new DisabledItemEventsScope()) {//Para evitar que ejecute una y otra vez el Evento ItemUpdating sobre este item itemOC.SystemUpdate(); } #endregion #region Actualizar bitacora //EjecutorOperacionesSP.ActualizarBitacoraAprobacion(itemOC); #endregion #region Notificacion por correo asuntoNotificacion = "Abastecimiento, orden de compra aprobada"; cuerpoNotificacion = this.CuerpoCorreoNotificacion(); usuariosNotificados = this.UsuariosANotificar(); usuariosCopiados = this.UsuariosACopiar(); mensajeHistorial = "Notificación por aprobación automática realizada exitosamente."; #endregion #region Iniciar el flujo 'Notificar Descuentos' EjecutorOperacionesSP.IniciarFlujoNotificarDescuentos(itemOC); #endregion } else { #region Notificacion por correo asuntoNotificacion = "Abastecimiento, solictud de aprobación"; cuerpoNotificacion = this.CuerpoCorreoSolicitud(); usuariosNotificados = this.UsuariosANotificar(); //usuariosCopiados = this.UsuariosACopiar(); mensajeHistorial = "Notificación a 'Aprobadores de OC' realizada exitosamente."; #endregion } } catch (Exception ex) { #region Registro de Evento Error LogEventos.LogArchivo log = new LogEventos.LogArchivo("LogErrores.txt"); log.WriteEvent("--- [FLUJO] RecuperarInformacion_ExecuteCode flujo 'Notificar aprobación' ---"); log.WriteException(ex); #endregion logNotificarAprobacion.EventId = SPWorkflowHistoryEventType.WorkflowError; logNotificarAprobacion.HistoryOutcome = "Error"; logNotificarAprobacion.HistoryDescription = ex.Message; } }
internal static SPFolder AddFolder(SPFolder parentFolder, string folderUrl) { SPFolder folder = Microsoft.Office.Server.Utilities.SPFolderHierarchy.GetSubFolder(parentFolder, folderUrl, true); SPListItem item = null; try { item = folder.Item; } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); } if (item != null) { SPModerationInformation moderationInformation = item.ModerationInformation; if (moderationInformation != null) { moderationInformation.Status = SPModerationStatusType.Approved; item.Update(); } } return(folder); }
public SPModerationInformationInstance(ObjectInstance prototype, SPModerationInformation moderationInformation) : this(prototype) { if (moderationInformation == null) { throw new ArgumentNullException("moderationInformation"); } m_moderationInformation = moderationInformation; }
private SPFolder EnsureFolder(SPList library, SPFolder parentFolder, FolderInfo folderInfo) { SPFolder folder = null; if (parentFolder == null) { // We are on at the root folder of the library (i.e. no parent folder). // Initialize defaults and pages in here, then move on to subfolders (instead of trying to create the folder) folder = library.RootFolder; // Ensure folder metadata defaults bool isDocumentLibrary = library.BaseType == SPBaseType.DocumentLibrary; if (folderInfo.FieldDefaultValues != null && folderInfo.FieldDefaultValues.Count > 0) { if (!isDocumentLibrary) { throw new ArgumentException("EnsureFolderHierarchy - Impossible to ensure folder MetadataDefaults on a list which is not a Document Library."); } this.valueWriter.WriteValuesToFolderDefaults(folder, folderInfo.FieldDefaultValues.ToList()); } else if (isDocumentLibrary) { ClearFolderAllFolderMetadataDefaults(folder); } // UniqueContentTypeOrder EnsureUniqueContentTypeOrder(folder, folderInfo); // Create pages if (folderInfo.Pages != null && folderInfo.Pages.Count > 0) { if ((int)library.BaseTemplate != BuiltInListTemplates.Pages.ListTempateTypeId) { // To provision Publishing Pages, you NEED to be inside the Pages library throw new ArgumentException("Publishing pages cannot be provisionned outside of the Pages library. Remove the PageInfo objects from your FolderInfo, or use this FolderInfo to provision content inside the Pages library instead."); } this.pageHelper.EnsurePage(library, folder, folderInfo.Pages); } // Create sub folders if (folderInfo.Subfolders != null && folderInfo.Subfolders.Count > 0) { library.EnableFolderCreation = true; library.Update(); foreach (var childFolder in folderInfo.Subfolders) { this.EnsureFolder(library, folder, childFolder); } } // Set Web HomePage if (folderInfo.WelcomePage != null) { var rootFolder = library.ParentWeb.RootFolder; rootFolder.WelcomePage = folderInfo.WelcomePage.LibraryRelativePageUrl.ToString(); rootFolder.Update(); } } else { if (!string.IsNullOrEmpty(folderInfo.Name)) { bool isDocumentLibrary = library.BaseType == SPBaseType.DocumentLibrary; try { if (isDocumentLibrary) { folder = parentFolder.SubFolders[folderInfo.Name]; } else { string serverRelativeFolderPathToMatch = SPUtility.ConcatUrls(parentFolder.ServerRelativeUrl, folderInfo.Name); folder = library.Folders.Cast <SPListItem>().Single(folderItem => folderItem.Folder.ServerRelativeUrl == serverRelativeFolderPathToMatch).Folder; } this.logger.Info("Skipping folder creation for " + folderInfo.Name + " because it already exists (will still apply values and default metadata)"); } catch (ArgumentException) { this.logger.Info("Creating liubrary folder " + folderInfo.Name); } catch (InvalidOperationException) { this.logger.Info("Creating list folder " + folderInfo.Name); } if (folder == null) { // Add the folder (if it doesn't already exist) if (isDocumentLibrary) { folder = parentFolder.SubFolders.Add(folderInfo.Name); } else { // In a non-doclib list, creating Folders needs to be done in another way (otherwise the SPFolder will not get an associated SPListItem) var folderItem = library.Items.Add(parentFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder); folderItem["Title"] = folderInfo.Name; folderItem.Update(); folder = folderItem.Folder; } } // Ensure folder metadata defaults if (folderInfo.FieldDefaultValues != null && folderInfo.FieldDefaultValues.Count > 0) { if (!isDocumentLibrary) { throw new ArgumentException("EnsureFolderHierarchy - Impossible to ensure folder MetadataDefaults on a list which is not a Document Library."); } this.valueWriter.WriteValuesToFolderDefaults(folder, folderInfo.FieldDefaultValues.ToList()); } else if (isDocumentLibrary) { ClearFolderAllFolderMetadataDefaults(folder); } // UniqueContentTypeInfo EnsureUniqueContentTypeOrder(folder, folderInfo); // Make sure the folder is published SPModerationInformation folderModerationInfo = folder.Item != null ? folder.Item.ModerationInformation : null; if (folderModerationInfo != null) { folderModerationInfo.Comment = "Automatically approved upon creation through Dynamite's FolderHelper utility."; folderModerationInfo.Status = SPModerationStatusType.Approved; folder.Item.Update(); } // Create pages if (folderInfo.Pages != null && folderInfo.Pages.Count > 0) { if ((int)library.BaseTemplate != BuiltInListTemplates.Pages.ListTempateTypeId) { // To provision Publishing Pages, you NEED to be inside the Pages library throw new ArgumentException("Publishing pages cannot be provisionned outside of the Pages library. Remove the PageInfo objects from your FolderInfo, or use this FolderInfo to provision content inside the Pages library instead."); } } this.pageHelper.EnsurePage(library, folder, folderInfo.Pages); } // Create sub folders foreach (var childFolder in folderInfo.Subfolders) { this.EnsureFolder(library, folder, childFolder); } } return(folder); }