public override void Provision(Microsoft.SharePoint.Client.ClientContext context, Microsoft.SharePoint.Client.Web web) { //get the web's property bag var props = web.AllProperties; context.Load(props); context.ExecuteQuery(); //set the ContosoBusinessImpact property and update props["ContosoBusinessImpact"] = cboSensitivity.SelectedValue; web.Update(); context.ExecuteQuery(); //call the base base.Provision(context, web); }
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope) { var isDirty = false; if (existingContentType.Hidden != templateContentType.Hidden) { scope.LogPropertyUpdate("Hidden"); existingContentType.Hidden = templateContentType.Hidden; isDirty = true; } if (existingContentType.ReadOnly != templateContentType.ReadOnly) { scope.LogPropertyUpdate("ReadOnly"); existingContentType.ReadOnly = templateContentType.ReadOnly; isDirty = true; } if (existingContentType.Sealed != templateContentType.Sealed) { scope.LogPropertyUpdate("Sealed"); existingContentType.Sealed = templateContentType.Sealed; isDirty = true; } if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description)) { scope.LogPropertyUpdate("Description"); existingContentType.Description = parser.ParseString(templateContentType.Description); isDirty = true; } if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate)) { scope.LogPropertyUpdate("DocumentTemplate"); existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate); isDirty = true; } if (existingContentType.Name != parser.ParseString(templateContentType.Name)) { scope.LogPropertyUpdate("Name"); existingContentType.Name = parser.ParseString(templateContentType.Name); isDirty = true; } if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group)) { scope.LogPropertyUpdate("Group"); existingContentType.Group = parser.ParseString(templateContentType.Group); isDirty = true; } if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } // Delta handling List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList(); List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList(); var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray(); if (fieldsNotPresentInTarget.Any()) { foreach (var fieldId in fieldsNotPresentInTarget) { var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); var field = web.Fields.GetById(fieldId); scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Adding_field__0__to_content_type, field.Id); web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden); } } isDirty = false; foreach (var fieldId in targetIds.Intersect(sourceIds)) { var fieldLink = existingContentType.FieldLinks.FirstOrDefault(fl => fl.Id == fieldId); var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); if (fieldRef != null) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Field__0__exists_in_content_type, fieldId); if (fieldLink.Required != fieldRef.Required) { scope.LogPropertyUpdate("Required"); fieldLink.Required = fieldRef.Required; isDirty = true; } if (fieldLink.Hidden != fieldRef.Hidden) { scope.LogPropertyUpdate("Hidden"); fieldLink.Hidden = fieldRef.Hidden; isDirty = true; } } } if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } }
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope) { var isDirty = false; if (existingContentType.Hidden != templateContentType.Hidden) { scope.LogPropertyUpdate("Hidden"); existingContentType.Hidden = templateContentType.Hidden; isDirty = true; } if (existingContentType.ReadOnly != templateContentType.ReadOnly) { scope.LogPropertyUpdate("ReadOnly"); existingContentType.ReadOnly = templateContentType.ReadOnly; isDirty = true; } if (existingContentType.Sealed != templateContentType.Sealed) { scope.LogPropertyUpdate("Sealed"); existingContentType.Sealed = templateContentType.Sealed; isDirty = true; } if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description)) { scope.LogPropertyUpdate("Description"); existingContentType.Description = parser.ParseString(templateContentType.Description); isDirty = true; } if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate)) { scope.LogPropertyUpdate("DocumentTemplate"); existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate); isDirty = true; } if (existingContentType.Name != parser.ParseString(templateContentType.Name)) { scope.LogPropertyUpdate("Name"); existingContentType.Name = parser.ParseString(templateContentType.Name); isDirty = true; // CT is being renamed, add an extra token to the tokenparser parser.AddToken(new ContentTypeIdToken(web, existingContentType.Name, existingContentType.StringId)); } if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group)) { scope.LogPropertyUpdate("Group"); existingContentType.Group = parser.ParseString(templateContentType.Group); isDirty = true; } if (templateContentType.DisplayFormUrl != null && existingContentType.DisplayFormUrl != parser.ParseString(templateContentType.DisplayFormUrl)) { scope.LogPropertyUpdate("DisplayFormUrl"); existingContentType.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl); isDirty = true; } if (templateContentType.EditFormUrl != null && existingContentType.EditFormUrl != parser.ParseString(templateContentType.EditFormUrl)) { scope.LogPropertyUpdate("EditFormUrl"); existingContentType.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl); isDirty = true; } if (templateContentType.NewFormUrl != null && existingContentType.NewFormUrl != parser.ParseString(templateContentType.NewFormUrl)) { scope.LogPropertyUpdate("NewFormUrl"); existingContentType.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl); isDirty = true; } #if !CLIENTSDKV15 if (templateContentType.Name.ContainsResourceToken()) { existingContentType.NameResource.SetUserResourceValue(templateContentType.Name, parser); isDirty = true; } if (templateContentType.Description.ContainsResourceToken()) { existingContentType.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser); isDirty = true; } #endif if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } // Delta handling existingContentType.EnsureProperty(c => c.FieldLinks); List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList(); List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList(); var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray(); if (fieldsNotPresentInTarget.Any()) { foreach (var fieldId in fieldsNotPresentInTarget) { var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); var field = web.Fields.GetById(fieldId); scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Adding_field__0__to_content_type, fieldId); web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden); } } isDirty = false; foreach (var fieldId in targetIds.Intersect(sourceIds)) { var fieldLink = existingContentType.FieldLinks.FirstOrDefault(fl => fl.Id == fieldId); var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); if (fieldRef != null) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Field__0__exists_in_content_type, fieldId); if (fieldLink.Required != fieldRef.Required) { scope.LogPropertyUpdate("Required"); fieldLink.Required = fieldRef.Required; isDirty = true; } if (fieldLink.Hidden != fieldRef.Hidden) { scope.LogPropertyUpdate("Hidden"); fieldLink.Hidden = fieldRef.Hidden; isDirty = true; } } } // The new CT is a DocumentSet, and the target should be, as well if (templateContentType.DocumentSetTemplate != null) { if (!Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.IsChildOfDocumentSetContentType(web.Context, existingContentType).Value) { scope.LogError(CoreResources.Provisioning_ObjectHandlers_ContentTypes_InvalidDocumentSet_Update_Request, existingContentType.Id, existingContentType.Name); } else { Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate templateToUpdate = Microsoft.SharePoint.Client.DocumentSet.DocumentSetTemplate.GetDocumentSetTemplate(web.Context, existingContentType); // TODO: Implement Delta Handling scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_DocumentSet_DeltaHandling_OnHold, existingContentType.Id, existingContentType.Name); } } if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } }
private void DeployWebWorkflowAssociationDefinition(WebModelHost modelHost, Microsoft.SharePoint.SPWeb web, WorkflowAssociationDefinition definition) { var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = existingWorkflowAssotiation, ObjectType = typeof(SPWorkflowAssociation), ObjectDefinition = definition, ModelHost = modelHost }); bool isNew = false; if (existingWorkflowAssotiation == null) { var workflowTemplate = GetWorkflowTemplate(modelHost, definition); if (workflowTemplate == null) { throw new SPMeta2Exception( string.Format("Cannot find workflow template by definition:[{0}]", definition)); } existingWorkflowAssotiation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, definition.Name, web.Lists[definition.TaskListTitle], web.Lists[definition.HistoryListTitle]); isNew = true; } MapProperties(definition, existingWorkflowAssotiation); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = existingWorkflowAssotiation, ObjectType = typeof(SPWorkflowAssociation), ObjectDefinition = definition, ModelHost = modelHost }); if (isNew) { web.WorkflowAssociations.Add(existingWorkflowAssotiation); web.Update(); } else { web.WorkflowAssociations.Update(existingWorkflowAssotiation); } }
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType) { var isDirty = false; if (existingContentType.Hidden != templateContentType.Hidden) { existingContentType.Hidden = templateContentType.Hidden; isDirty = true; } if (existingContentType.ReadOnly != templateContentType.ReadOnly) { existingContentType.ReadOnly = templateContentType.ReadOnly; isDirty = true; } if (existingContentType.Sealed != templateContentType.Sealed) { existingContentType.Sealed = templateContentType.Sealed; isDirty = true; } if (templateContentType.Description != null && existingContentType.Description != templateContentType.Description.ToParsedString()) { existingContentType.Description = templateContentType.Description.ToParsedString(); isDirty = true; } if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != templateContentType.DocumentTemplate.ToParsedString()) { existingContentType.DocumentTemplate = templateContentType.DocumentTemplate.ToParsedString(); isDirty = true; } if (existingContentType.Name != templateContentType.Name.ToParsedString()) { existingContentType.Name = templateContentType.Name.ToParsedString(); isDirty = true; } if (templateContentType.Group != null && existingContentType.Group != templateContentType.Group.ToParsedString()) { existingContentType.Group = templateContentType.Group.ToParsedString(); isDirty = true; } if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } // Delta handling List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList(); List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList(); var fieldsNotPresentInTarget = sourceIds.Except(targetIds).ToArray(); if (fieldsNotPresentInTarget.Any()) { foreach (var fieldId in fieldsNotPresentInTarget) { var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); var field = web.Fields.GetById(fieldId); web.AddFieldToContentType(existingContentType, field, fieldRef.Required, fieldRef.Hidden); } } isDirty = false; foreach (var fieldId in targetIds.Intersect(sourceIds)) { var fieldLink = existingContentType.FieldLinks.FirstOrDefault(fl => fl.Id == fieldId); var fieldRef = templateContentType.FieldRefs.Find(fr => fr.Id == fieldId); if (fieldRef != null) { if (fieldLink.Required != fieldRef.Required) { fieldLink.Required = fieldRef.Required; isDirty = true; } if (fieldLink.Hidden != fieldRef.Hidden) { fieldLink.Hidden = fieldRef.Hidden; isDirty = true; } } } if (isDirty) { existingContentType.Update(true); web.Context.ExecuteQueryRetry(); } }
/// <summary> /// Creates the type of the content. /// </summary> /// <param name="clientContext">The client context.</param> /// <param name="web">Object of site</param> /// <param name="siteColumns">The site columns.</param> /// <param name="contentTypeName">Name of Content Type</param> internal static bool CreateContentType(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, List<string> siteColumns, string contentTypeName, string contentTypegroup) { bool status = true; ContentType parentContentType = null; try { ContentTypeCollection contentTypeCollection = web.ContentTypes; clientContext.Load(contentTypeCollection); clientContext.Load(web.Fields); clientContext.ExecuteQuery(); parentContentType = (from ct in contentTypeCollection where ct.Name == ServiceConstantStrings.OneDriveParentContentType select ct).FirstOrDefault(); ContentTypeCreationInformation contentType = new ContentTypeCreationInformation(); contentType.Name = contentTypeName; contentType.Group = contentTypegroup; ///// contentType.Id = "0x010100B1ED198475FB3A4AABC59AAAD89B7EAD"; if (parentContentType != null) { contentType.ParentContentType = parentContentType; } ContentType finalObj = web.ContentTypes.Add(contentType); AddColumnsToContentType(web, siteColumns, finalObj); web.Update(); clientContext.ExecuteQuery(); } catch (Exception exception) { status = false; Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } return status; }
/// <summary> /// Creates site column. /// </summary> /// <param name="clientContext">Client Context</param> /// <param name="web">Object of site</param> /// <param name="siteColumns">List of site columns</param> /// <returns>Success or Failure</returns> internal static bool CreateSiteColumn(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, List<string> siteColumns) { bool result = false; try { FieldCollection fieldCol = web.Fields; clientContext.Load(fieldCol); clientContext.ExecuteQuery(); List<Field> existingFields = fieldCol.ToList<Field>(); foreach (string columns in siteColumns) { Field field = (from fld in existingFields where fld.Title == columns && fld.TypeAsString == ServiceConstantStrings.OneDriveSiteColumnType select fld).FirstOrDefault(); if (null == field) { web.Fields.AddFieldAsXml(string.Format(CultureInfo.InvariantCulture, ServiceConstantStrings.OneDriveSiteColumnSchema, ServiceConstantStrings.OneDriveSiteColumn, ServiceConstantStrings.OneDriveContentTypeGroup), true, AddFieldOptions.DefaultValue); web.Update(); clientContext.ExecuteQuery(); } } result = true; } catch (Exception exception) { Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); result = false; } return result; }
/// <summary> /// Determines whether the content type exists in the content type group under the specified client context. /// </summary> /// <param name="clientContext">Client context</param> /// <param name="web">Object of site</param> /// <param name="receivedContentType">Type of the received content</param> /// <param name="contentTypeGroup">The content type group</param> /// <param name="siteColumns">List of site columns</param> internal static bool IsContentTypePresentCheck(ClientContext clientContext, Microsoft.SharePoint.Client.Web web, string receivedContentType, string contentTypeGroup, List<string> siteColumns) { bool status = true; try { ContentTypeCollection contentTypeCollection = web.ContentTypes; clientContext.Load(contentTypeCollection, contentTypes => contentTypes.Include(contentTypeProperties => contentTypeProperties.Group, contentTypeProperties => contentTypeProperties.Name).Where(contentTypeValues => (contentTypeValues.Group == ServiceConstantStrings.OneDriveContentTypeGroup) && (contentTypeValues.Name == ServiceConstantStrings.OneDriveContentTypeName))); clientContext.ExecuteQuery(); if (0 < contentTypeCollection.Count) { FieldCollection fields = contentTypeCollection[0].Fields; clientContext.Load(fields, field => field.Include(fieldType => fieldType.Title).Where(column => column.Title == ServiceConstantStrings.OneDriveSiteColumn)); clientContext.ExecuteQuery(); if (0 == fields.Count) { BriefcaseContentTypeHelperFunctions.AddColumnsToContentType(web, siteColumns, contentTypeCollection[0]); web.Update(); clientContext.ExecuteQuery(); } } else { status = BriefcaseContentTypeHelperFunctions.CreateContentType(clientContext, web, siteColumns, receivedContentType, contentTypeGroup); } } catch (Exception exception) { status = false; Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName); } return status; }
/// <summary> /// Sends individual document to OneDrive /// </summary> /// <param name="clientContext">SP client context</param> /// <param name="collectionOfAttachments">Dictionary object containing attachment URLs and their stream data</param> /// <param name="listItemsColl">List item collection of Legal Briefcase folder</param> /// <param name="allAttachmentUrl">A string array containing all the attachment URLs</param> /// <param name="web">Object of site</param> /// <param name="usersMySite">My Site URL of the user</param> /// <param name="collectionOfOriginalAttachments">Dictionary object containing attachment URLs</param> /// <param name="defaultContentTypeId">Default content type Id</param> /// <param name="status">Status of documents sent to OneDrive</param> /// <returns>Status of documents sent to OneDrive</returns> internal static string SendIndividualDocument(ClientContext clientContext, Dictionary<string, Stream> collectionOfAttachments, ListItemCollection listItemsColl, string[] allAttachmentUrl, Microsoft.SharePoint.Client.Web web, string usersMySite, Dictionary<string, string> collectionOfOriginalAttachments, string defaultContentTypeId, string status) { int documentCount = 0, count = 0; string fileNameKey = string.Empty; string overwriteDocumentURLs = string.Empty; foreach (string key in collectionOfAttachments.Keys) { fileNameKey = key.Split(new string[] { ConstantStrings.DOLLAR }, StringSplitOptions.RemoveEmptyEntries)[0]; var selectedItems = from li in listItemsColl.Cast<ListItem>() from files in li.Folder.Files where files.Name.ToUpperInvariant() == fileNameKey.ToUpperInvariant() select files; if (selectedItems.FirstOrDefault() != null) { overwriteDocumentURLs += allAttachmentUrl[count] + ConstantStrings.Semicolon; } else { SendDocumentToOneDrive(web, usersMySite, fileNameKey, collectionOfAttachments[key], collectionOfOriginalAttachments[key], defaultContentTypeId); documentCount++; } count++; web.Update(); clientContext.ExecuteQuery(); MailAttachmentDetails.CheckoutFailedPosition++; status = string.Concat(usersMySite, ServiceConstantStrings.OneDriveDocumentLibraryTitle, ConstantStrings.Semicolon, documentCount, ConstantStrings.Semicolon, collectionOfAttachments.Count, ConstantStrings.Semicolon, overwriteDocumentURLs); } return status; }