public async Task CreateUnifiedGroupsForPropertiesAsync(GraphService graphService) { var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties")); var members = new List <IUser>(); { var dispatcher = await graphService.GetFirstUserAsync(u => u.mail == AppSettings.DispatcherEmail); var inspectors = await graphService.GetGroupMembersAsync("Inspectors"); var repairPeople = await graphService.GetGroupMembersAsync("Repair People"); if (dispatcher != null) { members.Add(dispatcher); } members.AddRange(inspectors); members.AddRange(repairPeople); } foreach (var property in await properties) { var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]); if (group == null) { group = await CreateUnifiedGroupForPropertyAsync(graphService, property, members); } property["sl_group"] = group.objectId; property.Update(); } clientContext.ExecuteQuery(); }
public async Task AddSiteContentsAsync(VideoPortalHelper videoPortalHelper) { replaceTenantId(sampleData); //add items to Properties list CSOMUtil.AddListItems(clientContext, "Properties", sampleData); //add items to Rooms list CSOMUtil.AddListItems(clientContext, "Rooms", sampleData); //add items to Inspections list CSOMUtil.AddListItems(clientContext, "Inspections", sampleData); //add items to Inspection Comments list CSOMUtil.AddListItems(clientContext, "Inspection Comments", sampleData); //add items to Incidents list CSOMUtil.AddListItems(clientContext, "Incidents", sampleData); //add items to Room Inspection Photos list CSOMUtil.AddDocumentLibItems(clientContext, "Room Inspection Photos", sampleData); //add items to Repair Photos list CSOMUtil.AddDocumentLibItems(clientContext, "Repair Photos", sampleData); //add items to Property Photos list CSOMUtil.AddDocumentLibItems(clientContext, "Property Photos", sampleData); //upload demo videos to Video Portal await ProvisionDemoVideosAsync(videoPortalHelper, "Videos", sampleData); }
public void RemoveSiteComponents() { //Delete lists CSOMUtil.RemoveSharePointList(clientContext, "Properties"); CSOMUtil.RemoveSharePointList(clientContext, "Rooms"); CSOMUtil.RemoveSharePointList(clientContext, "Inspections"); CSOMUtil.RemoveSharePointList(clientContext, "Inspection Comments"); CSOMUtil.RemoveSharePointList(clientContext, "Incidents"); CSOMUtil.RemoveSharePointList(clientContext, "Room Inspection Photos"); CSOMUtil.RemoveSharePointList(clientContext, "Repair Photos"); CSOMUtil.RemoveSharePointList(clientContext, "Property Photos"); //Delete content types CSOMUtil.RemoveContentType(clientContext, "0x0100EF599D47A3D2409193AC8276BE6DECB8"); CSOMUtil.RemoveContentType(clientContext, "0x0100DA7D2213C0CC4C4782C9C50DE696DB86"); CSOMUtil.RemoveContentType(clientContext, "0x0100981711E5CE33481C85F37734423082DB"); CSOMUtil.RemoveContentType(clientContext, "0x0100D2E3A1E1221041048FCCF4ACA70716FC"); CSOMUtil.RemoveContentType(clientContext, "0x01001D53426644A048A7A6E29683A8351143"); CSOMUtil.RemoveContentType(clientContext, "0x0100232C3EC9E48A4838983CC2F8FFB3D8E3"); CSOMUtil.RemoveContentType(clientContext, "0x0100B34132E48D364D4781878210F1663255"); CSOMUtil.RemoveContentType(clientContext, "0x010100ECBC5A98AA6F42729342F940B0F10493"); CSOMUtil.RemoveContentType(clientContext, "0x010100F15273431C9143FCBA2C914F293399E9"); CSOMUtil.RemoveContentType(clientContext, "0x0101006C010CC23D0643E3AADDC173CE461770"); //Delete site columns CSOMUtil.RemoveSiteColumns(clientContext, _siteColumns); }
/// <summary> /// Bind a lookup field to the target list /// </summary> public static void BindLookupField(ClientContext clientContext, string sourceListTitle, string lookupFieldName, string lookupDisplayFieldName, string lookupListTitle) { var sourceList = CSOMUtil.GetListByTitle(clientContext, sourceListTitle); var lookupList = CSOMUtil.GetListByTitle(clientContext, lookupListTitle); if (sourceList != null && lookupList != null) { var fieldColl = sourceList.Fields; var q = clientContext.LoadQuery <Field>(fieldColl.Where(n => n.InternalName == lookupFieldName)); clientContext.ExecuteQuery(); if (q.Count() > 0) { var field = q.FirstOrDefault <Field>() as FieldLookup; field.LookupList = lookupList.Id.ToString(); field.LookupField = lookupDisplayFieldName; field.Update(); clientContext.ExecuteQuery(); } } }
/// <summary> /// Create Content Type /// </summary> public static void CreateContentType(ClientContext clientContext, string ContentTypeName, string ContentTypeDescription, string ContentTypeId, string[] filedNames) { var contentType = CSOMUtil.GetContentTypeById(clientContext, ContentTypeId); // check if the content type exists if (contentType == null) { ContentTypeCollection contentTypeColl = clientContext.Web.ContentTypes; clientContext.Load(contentTypeColl); clientContext.ExecuteQuery(); // Specifies properties that are used as parameters to initialize a new content type. ContentTypeCreationInformation contentTypeCreation = new ContentTypeCreationInformation(); contentTypeCreation.Name = ContentTypeName; contentTypeCreation.Description = ContentTypeDescription; contentTypeCreation.Group = "Property Manager My App Content Types"; contentTypeCreation.Id = ContentTypeId; //// Add the new content type to the collection contentType = contentTypeColl.Add(contentTypeCreation); clientContext.Load(contentType); clientContext.ExecuteQuery(); CSOMUtil.BindFieldsToContentType(clientContext, contentType, filedNames); } }
public void AddSiteContents() { XmlDocument sampleData = new XmlDocument(); var sampleDataUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + "/Content/SampleData.xml"; sampleData.Load(sampleDataUrl); replaceTenantId(sampleData); //add items to Properties list CSOMUtil.AddListItems(_clientContext, "Properties", sampleData); //add items to Rooms list CSOMUtil.AddListItems(_clientContext, "Rooms", sampleData); //add items to Inspections list CSOMUtil.AddListItems(_clientContext, "Inspections", sampleData); //add items to Inspection Comments list CSOMUtil.AddListItems(_clientContext, "Inspection Comments", sampleData); //add items to Incidents list CSOMUtil.AddListItems(_clientContext, "Incidents", sampleData); //add items to Room Inspection Photos list CSOMUtil.AddDocumentLibItems(_clientContext, "Room Inspection Photos", sampleData); //add items to Repair Photos list CSOMUtil.AddDocumentLibItems(_clientContext, "Repair Photos", sampleData); //add items to Property Photos list CSOMUtil.AddDocumentLibItems(_clientContext, "Property Photos", sampleData); }
private void AddUsersToSPGroup(List <string> newUsers) { if (newUsers != null && newUsers.Count > 0) { foreach (string loginName in newUsers) { CSOMUtil.AddUserToSPGroup(clientContext, loginName); } } }
/// <summary> /// Create Content Type /// </summary> public static void RemoveContentType(ClientContext clientContext, string ContentTypeId) { var contentType = CSOMUtil.GetContentTypeById(clientContext, ContentTypeId); if (contentType != null) { contentType.DeleteObject(); clientContext.ExecuteQuery(); } }
/// <summary> /// Remove a list/document library in o365 web /// </summary> public static void RemoveSharePointList(ClientContext clientContext, string listTitle) { var list = CSOMUtil.GetListByTitle(clientContext, listTitle); // check if the content type exists if (list != null) { list.DeleteObject(); clientContext.ExecuteQuery(); } }
public void RemoveIncidentWorkflowAndRelatedLists() { var incidentsList = CSOMUtil.GetListByTitle(clientContext, "Incidents"); var service = new WorkflowProvisionService(clientContext); service.Unsubscribe(incidentsList.Id, "Incident"); service.DeleteDefinitions("Incident"); service.DeleteList("Incident Workflow Tasks"); service.DeleteList("Incident Workflow History"); }
public void ProvisionIncidentWorkflowAndRelatedLists(string incidentWorkflowFile, string suiteLevelWebAppUrl, string dispatcherName) { var incidentsList = CSOMUtil.GetListByTitle(clientContext, "Incidents"); var service = new WorkflowProvisionService(clientContext); var incidentWF = System.IO.File.ReadAllText(incidentWorkflowFile) .Replace("(SuiteLevelWebAppUrlPlaceholder)", suiteLevelWebAppUrl) .Replace("(dispatcherPlaceHolder)", dispatcherName); var incidentWFDefinitionId = service.SaveDefinitionAndPublish("Incident", WorkflowUtil.TranslateWorkflow(incidentWF)); var taskListId = service.CreateTaskList("Incident Workflow Tasks"); var historyListId = service.CreateHistoryList("Incident Workflow History"); service.Subscribe("Incident Workflow", incidentWFDefinitionId, incidentsList.Id, WorkflowSubscritpionEventType.ItemAdded, taskListId, historyListId); }
public async Task CreateUnifiedGroupsForPropertiesAsync(GraphServiceClient graphService, string graphAccessToken) { var properties = Task.Run(() => CSOMUtil.GetListItems(clientContext, "Properties")); var members = new List <Graph.User>(); { var queryUsers = (await graphService.Users.Request().Filter(string.Format("mail eq '{0}'", AppSettings.DispatcherEmail)).GetAsync()).CurrentPage; var dispatcher = queryUsers.Count > 0 ? queryUsers[0]: null; if (dispatcher == null) { return; } var inspectors = await graphService.GetGroupMembersAsync("Inspectors"); var repairPeople = await graphService.GetGroupMembersAsync("Repair People"); if (dispatcher != null) { members.Add(dispatcher); } members.AddRange(inspectors); members.AddRange(repairPeople); } foreach (var property in await properties) { var group = await graphService.GetGroupByDisplayNameAsync((string)property["Title"]); if (group == null) { group = await CreateUnifiedGroupForPropertyAsync(graphService, graphAccessToken, property, members); } property["sl_group"] = group.Id; property.Update(); } clientContext.ExecuteQuery(); await UpdateGroupPhotoAsync(graphService); }
public string CreateSiteCollection(ClientContext context) { string creatingStatus = string.Empty; switch (CSOMUtil.GetSiteCollectionStatusByUrl(context, AppSettings.DemoSiteCollectionUrl)) { case "Active": creatingStatus = "created"; break; case "Creating": creatingStatus = "creating"; break; case "None": try { creatingStatus = "creating"; CSOMUtil.CreateSiteCollection(context, new SiteCreationProperties { Url = AppSettings.DemoSiteCollectionUrl, Owner = AppSettings.DemoSiteCollectionOwner, Template = "BLANKINTERNETCONTAINER#0", Title = "Contoso Property Management Dashboard", StorageMaximumLevel = 1000, StorageWarningLevel = 750, TimeZoneId = 7, UserCodeMaximumLevel = 1000, UserCodeWarningLevel = 500 }); } catch { creatingStatus = "fail"; } break; } return(creatingStatus); }
/// <summary> /// Create Site Columns using field xml declaration /// </summary> public static void CreateSiteColumns(ClientContext clientContext, string[] fieldXMLDefinations) { var fields = clientContext.Web.Fields; foreach (string fieldXML in fieldXMLDefinations) { Regex matchGuid = new Regex("{\\S*}"); var match = matchGuid.Match(fieldXML); if (match.Success) { var fieldID = new Guid(match.Value); var field = CSOMUtil.GetFieldById(clientContext, fieldID); // Check if the field exists if (field == null) { clientContext.Web.Fields.AddFieldAsXml(fieldXML, true, AddFieldOptions.AddFieldInternalNameHint); clientContext.ExecuteQuery(); } } } }
/// <summary> /// Remove Site Columns /// </summary> public static void RemoveSiteColumns(ClientContext clientContext, string[] fieldXMLDefinations) { var fields = clientContext.Web.Fields; foreach (string fieldXML in fieldXMLDefinations) { Regex matchGuid = new Regex("{\\S*}"); var match = matchGuid.Match(fieldXML); if (match.Success) { var fieldID = new Guid(match.Value); var field = CSOMUtil.GetFieldById(clientContext, fieldID); // Check if the field exists // and can be deleted if (field != null && field.CanBeDeleted) { field.DeleteObject(); clientContext.ExecuteQuery(); } } } }
public void AddSiteComponents() { // Create site columns CSOMUtil.CreateSiteColumns(clientContext, _siteColumns); // Create Content Type "Property" and List "Properties" CSOMUtil.CreateContentType(clientContext, "Property", "", "0x0100DA7D2213C0CC4C4782C9C50DE696DB86", new string[] { "sl_owner", "sl_emailaddress", "sl_address1", "sl_address2", "sl_city", "sl_state", "sl_postalCode", "sl_latitude", "sl_longitude", "sl_group" }); CSOMUtil.AddSharePointList(clientContext, "0x0100DA7D2213C0CC4C4782C9C50DE696DB86", "Properties", "Lists/Properties", (int)ListTemplateType.GenericList); // Create Content Type "Room" and List "Rooms" CSOMUtil.CreateContentType(clientContext, "Room", "", "0x0100981711E5CE33481C85F37734423082DB", new string[] { "sl_propertyID" }); CSOMUtil.AddSharePointList(clientContext, "0x0100981711E5CE33481C85F37734423082DB", "Rooms", "Lists/Rooms", (int)ListTemplateType.GenericList); CSOMUtil.BindLookupField(clientContext, "Rooms", "sl_propertyID", "ID", "Properties"); // Create Content Type "Inspection" and List "Inspections" CSOMUtil.CreateContentType(clientContext, "Inspection", "", "0x01001D53426644A048A7A6E29683A8351143", new string[] { "sl_datetime", "sl_inspector", "sl_emailaddress", "sl_propertyID", "sl_finalized" }); CSOMUtil.AddSharePointList(clientContext, "0x01001D53426644A048A7A6E29683A8351143", "Inspections", "Lists/Inspections", (int)ListTemplateType.GenericList, true); CSOMUtil.BindLookupField(clientContext, "Inspections", "sl_propertyID", "ID", "Properties"); // Create Content Type "Inspection Comment" and List "Inspection Comments" CSOMUtil.CreateContentType(clientContext, "Inspection Comment", "", "0x0100232C3EC9E48A4838983CC2F8FFB3D8E3", new string[] { "sl_inspectionID", "sl_roomID" }); CSOMUtil.AddSharePointList(clientContext, "0x0100232C3EC9E48A4838983CC2F8FFB3D8E3", "Inspection Comments", "Lists/InspectionComments", (int)ListTemplateType.GenericList); CSOMUtil.BindLookupField(clientContext, "Inspection Comments", "sl_inspectionID", "ID", "Inspections"); CSOMUtil.BindLookupField(clientContext, "Inspection Comments", "sl_roomID", "ID", "Rooms"); // Create Content Type "Incident" and List "Incidents" CSOMUtil.CreateContentType(clientContext, "Incident", "", "0x0100B34132E48D364D4781878210F1663255", new string[] { "sl_date", "sl_inspectorIncidentComments", "sl_dispatcherComments", "sl_repairComments", "sl_status", "sl_repairScheduled", "sl_repairCompleted", "sl_repairApproved", "sl_repairPerson", "sl_propertyID", "sl_inspectionID", "sl_roomID", "sl_type", "sl_taskId" }); CSOMUtil.AddSharePointList(clientContext, "0x0100B34132E48D364D4781878210F1663255", "Incidents", "Lists/Incidents", (int)ListTemplateType.GenericList); CSOMUtil.BindLookupField(clientContext, "Incidents", "sl_propertyID", "ID", "Properties"); CSOMUtil.BindLookupField(clientContext, "Incidents", "sl_inspectionID", "ID", "Inspections"); CSOMUtil.BindLookupField(clientContext, "Incidents", "sl_roomID", "ID", "Rooms"); // Create Content Type "Room Inspection Photo" and Document Lib "Room Inspection Photos" CSOMUtil.CreateContentType(clientContext, "Room Inspection Photo", "", "0x010100ECBC5A98AA6F42729342F940B0F10493", new string[] { "sl_inspectionID", "sl_incidentID", "sl_roomID" }); CSOMUtil.AddSharePointList(clientContext, "0x010100ECBC5A98AA6F42729342F940B0F10493", "Room Inspection Photos", "RoomInspectionPhotos", (int)ListTemplateType.DocumentLibrary); CSOMUtil.BindLookupField(clientContext, "Room Inspection Photos", "sl_inspectionID", "ID", "Inspections"); CSOMUtil.BindLookupField(clientContext, "Room Inspection Photos", "sl_incidentID", "ID", "Incidents"); CSOMUtil.BindLookupField(clientContext, "Room Inspection Photos", "sl_roomID", "ID", "Rooms"); // Create Content Type "Repair Photo" and Document Lib "Repair Photos" CSOMUtil.CreateContentType(clientContext, "Repair Photo", "", "0x010100F15273431C9143FCBA2C914F293399E9", new string[] { "sl_inspectionID", "sl_incidentID", "sl_roomID" }); CSOMUtil.AddSharePointList(clientContext, "0x010100F15273431C9143FCBA2C914F293399E9", "Repair Photos", "RepairPhotos", (int)ListTemplateType.DocumentLibrary); CSOMUtil.BindLookupField(clientContext, "Repair Photos", "sl_inspectionID", "ID", "Inspections"); CSOMUtil.BindLookupField(clientContext, "Repair Photos", "sl_incidentID", "ID", "Incidents"); CSOMUtil.BindLookupField(clientContext, "Repair Photos", "sl_roomID", "ID", "Rooms"); // Create Content Type "Property Photo" and Document Lib "Property Photos" CSOMUtil.CreateContentType(clientContext, "Property Photo", "", "0x0101006C010CC23D0643E3AADDC173CE461770", new string[] { "sl_propertyID" }); CSOMUtil.AddSharePointList(clientContext, "0x0101006C010CC23D0643E3AADDC173CE461770", "Property Photos", "PropertyPhotos", (int)ListTemplateType.DocumentLibrary); CSOMUtil.BindLookupField(clientContext, "Property Photos", "sl_propertyID", "ID", "Properties"); }
/// <summary> /// Add a list/document library to o365 web /// </summary> public static void AddSharePointList(ClientContext clientContext, string contentTypeID, string listTitle, string url, int listTemplateType, bool isHideTitle = false) { Web web = clientContext.Web; var contentType = CSOMUtil.GetContentTypeById(clientContext, contentTypeID); var list = CSOMUtil.GetListByTitle(clientContext, listTitle); // check if the content type exists if (list == null && contentType != null) { ListCreationInformation creationInfo = new ListCreationInformation(); creationInfo.Title = listTitle; creationInfo.Url = url; creationInfo.TemplateType = listTemplateType; list = web.Lists.Add(creationInfo); list.Update(); clientContext.ExecuteQuery(); // insert content type var cts = list.ContentTypes; list.ContentTypesEnabled = true; cts.AddExistingContentType(contentType); clientContext.Load(cts); clientContext.ExecuteQuery(); // remove default content type var count = cts.Count; while (--count >= 0) { if (cts[0].Name != "Folder" && cts[0].Name != contentType.Name) { cts[0].DeleteObject(); } } clientContext.ExecuteQuery(); // add fields to default view View defaultView = list.DefaultView; clientContext.Load(defaultView, v => v.ViewFields); clientContext.Load(contentType, c => c.Fields); clientContext.ExecuteQuery(); if (!defaultView.ViewFields.Contains("ID")) { defaultView.ViewFields.Add("ID"); defaultView.ViewFields.MoveFieldTo("ID", 0); } //hide title field in view if (isHideTitle == true) { defaultView.ViewFields.Remove("LinkTitle"); } foreach (Field field in contentType.Fields) { if (!defaultView.ViewFields.Contains(field.Title) && field.Title != "Content Type" && field.Title != "Title") { defaultView.ViewFields.Add(field.Title); } } defaultView.Update(); clientContext.ExecuteQuery(); //hide title field in forms if (isHideTitle == true) { var field_title = list.Fields.GetByTitle("Title"); clientContext.Load(field_title); clientContext.ExecuteQuery(); field_title.Hidden = true; field_title.Update(); clientContext.ExecuteQuery(); } } }