private bool AssignPermssionDesigner(string listTitle, string accountAdd) { if (!UtilApp.IsExist(context, listTitle, Basic_CSOM.Enums.TypeSharepointEnum.List)) { return(false); } // get list var oList = context.Web.Lists.GetByTitle(listTitle); // break role permission oList.BreakRoleInheritance(false, true); Web web = context.Web; //context.Load(web, a => a.SiteUsers); context.ExecuteQuery(); // Change permission Principal user = web.SiteUsers.GetByEmail(accountAdd); var designRole = new RoleDefinitionBindingCollection(context); designRole.Add(context.Web.RoleDefinitions.GetByType(RoleType.WebDesigner)); oList.RoleAssignments.Add(user, designRole); //context.Load(newRoleAssignment); context.ExecuteQuery(); return(true); }
public override void UpdateListitemLookup(List list, ListCollection webListCollection, ContentType contentType) { var relatedList = webListCollection.GetByTitle(DependListTitle); if (relatedList == null || !UtilApp.IsExist(context, DependListTitle, Basic_CSOM.Enums.TypeSharepointEnum.List)) { return; } context.Load(relatedList, li => li.Id); context.ExecuteQuery(); string schema = $"<Field ID='{Guid.NewGuid()}' Type='Lookup' Name='Leader' StaticName='Leader' DisplayName='Leader' List='{relatedList.Id}' ShowField='Title' />"; Field leaderField = list.Fields.AddFieldAsXml(schema, true, AddFieldOptions.AddFieldInternalNameHint); leaderField.SetShowInEditForm(true); leaderField.SetShowInNewForm(true); context.Load(leaderField); UpdateFieldToContentType(contentType, leaderField, "Leader"); // Add member field string memberFieldSchema = $"<Field ID='{Guid.NewGuid()}' Type='LookupMulti' Name='Member' StaticName='Member' DisplayName='Member' List='{relatedList.Id}' ShowField='Title' Mult='TRUE' />"; Field memberField = list.Fields.AddFieldAsXml(memberFieldSchema, true, AddFieldOptions.AddFieldInternalNameHint); memberField.SetShowInEditForm(true); memberField.SetShowInNewForm(true); context.Load(memberField); UpdateFieldToContentType(contentType, memberField, "Member"); // Add metadata field // Create as a regular field setting the desired type in XML string metatSchema = $"<Field DisplayName='New State' Name='DemoNewState' ID='{Guid.NewGuid()}' ShowField='Title' Type='TaxonomyFieldTypeMulti' />"; Field field = list.Fields.AddFieldAsXml(metatSchema, false, AddFieldOptions.AddFieldInternalNameHint); context.ExecuteQuery(); Guid termStoreId = Guid.Empty; Guid termSetId = Guid.Empty; GetTaxonomyFieldInfo("DepartmentSet", out termStoreId, out termSetId); // Retrieve as Taxonomy Field TaxonomyField taxonomyField = context.CastTo <TaxonomyField>(field); taxonomyField.SspId = termStoreId; taxonomyField.TermSetId = termSetId; taxonomyField.TargetTemplate = String.Empty; taxonomyField.AnchorId = Guid.Empty; taxonomyField.Update(); UpdateFieldToContentType(contentType, taxonomyField, "DepartmentTest"); list.Update(); }
public ProjectDocListPage(ClientContext context, string listName = "Project Document List") { InitializeComponent(); this.context = context; if (UtilApp.IsExist(context, listName, Enums.TypeSharepointEnum.List)) { Load(listName); } else { MessageBox.Show($"List name {listName} is not existed"); } }
public EmployeeListPage(ClientContext context, string listName = "EmployeeList") { InitializeComponent(); this.context = context; Employees = new ObservableCollection <Employee>(); if (UtilApp.IsExist(context, listName, Enums.TypeSharepointEnum.List)) { Load(listName); } else { MessageBox.Show($"List name {listName} is not existed"); } }
private void CreateList <T>(string name, string contentType) where T : BaseList { if (UtilApp.IsExist(context, name, Enums.TypeSharepointEnum.List)) { MessageBox.Show("List is existed. Please change the another name", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); } else { var instance = (BaseList)Activator.CreateInstance(typeof(T), context); instance.Title = name; instance.ContentTypeName = contentType; currentList = instance.Generate(); MessageBox.Show("List is created successfully", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); } }
private void ProjectDocContentType_OnClick(object sender, RoutedEventArgs e) { string name = ProjectDocContentTypeName.Text.ToString().Trim(); if (UtilApp.IsExist(context, name, Enums.TypeSharepointEnum.ContentType)) { MessageBox.Show("Content type is existed. Please change the another name", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); } else { ProjectDocumentContentTypeTemplate template = new ProjectDocumentContentTypeTemplate(context) { Name = name }; template.Create(); MessageBox.Show("Content type is created successfully", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); } }
public override Field Create() { var filed = GetField(); if (filed != null) { // Existed this site column return(filed); } if (UtilApp.IsExist(Context, DisplayName, TypeSharepointEnum.SiteColumn)) { return(null); } var web = Context.Web; Field newField = web.Fields.AddFieldAsXml(SchemaXml, false, AddFieldOptions.AddFieldInternalNameHint); Context.Load(web); Context.Load(newField); Context.ExecuteQuery(); return(newField); }