public static void ProvisionSiteCollection() { try { //Check if Site Collection is exist var siteCtx = AuthHelper.GetClientContext(); bool isSiteExist = false; // This will not check if Site Collection is deleted and available in Recycle bin if (siteCtx.WebExistsFullUrl(AuthHelper.siteUrl)) { isSiteExist = true; } //Create Context of SPO Admin var tenantCtx = AuthHelper.GetTenantContext(); var tenant = new Tenant(tenantCtx); SpoOperation spo = null; if (isSiteExist) { DeleteSiteCollectionAndRecycled(spo, tenantCtx, tenant); RemoveSiteFromRecycleBin(spo, tenantCtx, tenant); } else { CreateSiteCollection(spo, tenantCtx, tenant); } } catch (Exception) { throw; } }
public static void ValidateAndCreateListAndLibrry() { // ClientContext - Get the context for the SharePoint Site var clientContext = AuthHelper.GetClientContext(); clientContext.ExecuteQuery(); var listDetails = new Data().GetListInfo().Keys; var libraryDetails = new Data().GetLibInfo().Keys; // Create List foreach (string listName in listDetails) { if (!String.IsNullOrEmpty(listName.Trim())) { string templateType = "List"; int count = Helper.IsExist_Helper(clientContext, listName, "list"); if (count == 0) { CreateListLibrary(clientContext, listName, templateType); } else { DeleteListAndLibrary(clientContext, listName); CreateListLibrary(clientContext, listName, templateType); } } } //Create Library foreach (string libName in libraryDetails) { if (!String.IsNullOrEmpty(libName.Trim())) { string templateType = "Library"; int count = Helper.IsExist_Helper(clientContext, libName, "list"); if (count == 0) { CreateListLibrary(clientContext, libName, templateType); } else { DeleteListAndLibrary(clientContext, libName); CreateListLibrary(clientContext, libName, templateType); } } } }
public static void ValidateAndCreateContentType() { var clientContext = AuthHelper.GetClientContext(); Web oWeb = clientContext.Web; var contentTypeDetails = new Data().GetListInfo().Values.ToList(); CreateContentType(clientContext, oWeb, contentTypeDetails, "List"); var contentTypeDetailsForLib = new Data().GetLibInfo().Values.ToList(); CreateContentType(clientContext, oWeb, contentTypeDetailsForLib, "Library"); //contentTypeDetailsForLib.ForEach(x => //{ // contentTypeDetails.Add(x); //}); }
public static void ValidateAndAssociateContenTypeToList() { var clientContext = AuthHelper.GetClientContext(); Web oweb = clientContext.Web; var listDetails = new Data().GetListInfo(); var libraryDetails = new Data().GetLibInfo(); //Push the data from libraryDetails to listDetails libraryDetails.ToList().ForEach(x => listDetails.Add(x.Key, x.Value)); listDetails.ToDictionary(x => x.Key); var contentTypeDetails = listDetails.Values.ToList(); //iterate from the listDetails and associate content Type with the list //value is Content type and key is List name for (int i = 0, j = 0; i < listDetails.Keys.Count(); i++, j++) { var listName = listDetails.Keys.ToList()[i]; foreach (var contentTypeName in contentTypeDetails[j].Keys) { var contentTypeID = ContentTypeHelper.GetContentTypeIdByName(clientContext, contentTypeName); bool isAssociated = oweb.ContentTypeExistsByName(listName, contentTypeName); if (!isAssociated) { AssociateContentTypeToList(clientContext, oweb, listName, contentTypeID, contentTypeName); SetDefaultContentType(clientContext, oweb, listName, contentTypeID, contentTypeName); } else { Console.WriteLine(contentTypeName + " Content Type already Associated to " + listName + " List/Library"); } break; } } }
internal static void UploadFoldersRecursively(string sourceFolder, string destinationLibraryTitle) { var clientContext = AuthHelper.GetClientContext(); Web web = clientContext.Web; var query = clientContext.LoadQuery(web.Lists.Where(p => p.Title == destinationLibraryTitle)); clientContext.ExecuteQuery(); List documentsLibrary = query.FirstOrDefault(); var folder = documentsLibrary.RootFolder; System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sourceFolder); clientContext.Load(documentsLibrary.RootFolder); clientContext.ExecuteQuery(); folder = documentsLibrary.RootFolder.Folders.Add(di.Name); clientContext.ExecuteQuery(); UploadFolder(clientContext, di, folder); }
public static void ValidateAndAddSiteColumnToContentType() { var clientContext = AuthHelper.GetClientContext(); Web oWeb = clientContext.Web; var contentTypeDetails = new Data().GetListInfo().Values.ToList(); var contentTypeDetailsForLib = new Data().GetLibInfo().Values.ToList(); contentTypeDetailsForLib.ForEach(x => { contentTypeDetails.Add(x); }); foreach (var ctDetails in contentTypeDetails) { for (int i = 0; i < ctDetails.Count(); i++) { var contentTypeName = ctDetails.ToList()[i].Key; var siteColumnDetails = ctDetails.ToList()[i].Value; foreach (string columnName in siteColumnDetails) { Console.WriteLine(columnName); bool isExist = oWeb.FieldExistsByNameInContentType(contentTypeName, columnName); if (isExist) { RemoveFieldFromContentType(clientContext, oWeb, columnName, contentTypeName); AddFieldToContentType(clientContext, oWeb, columnName, contentTypeName); } else { AddFieldToContentType(clientContext, oWeb, columnName, contentTypeName); } } } } }
public static void UpdateLookUpSiteColumn() { var context = AuthHelper.GetClientContext(); Web oWeb = context.Web; var listOfLookUpSiteColumnDetails = GetLookUpSiteColumnInfo(context, oWeb); foreach (var x in listOfLookUpSiteColumnDetails) { Field oField = context.Web.Fields.GetByInternalNameOrTitle(x.Name); context.Load(oField, f => f.SchemaXml); context.ExecuteQuery(); oField.SchemaXml = "<Field Type='Lookup' WebId='" + oWeb.Id + "' Name ='" + x.Name + "' StaticName='" + x.Name + "' DisplayName='" + x.DisplayName + "' List = '" + x.List + "' ShowField = '" + x.ShowField + "' /> "; context.Load(oField); context.ExecuteQuery(); Console.WriteLine(x.Name + " SchemaXml has been updated with WebId"); Console.WriteLine(x.Name + " = " + oField.SchemaXml); Console.WriteLine("************************************"); Console.WriteLine(); } }
public static void ValidateAndCreateSiteColumn() { var clientContext = AuthHelper.GetClientContext(); Web oWeb = clientContext.Web; clientContext.Load(oWeb, w => w.Id); List EntityList = clientContext.Web.Lists.GetByTitle("Entity"); clientContext.Load(EntityList, e => e.Id); List JurisdictionList = clientContext.Web.Lists.GetByTitle("Jurisdiction"); clientContext.Load(JurisdictionList, j => j.Id); List keyProcessList = clientContext.Web.Lists.GetByTitle("KeyProcess"); clientContext.Load(keyProcessList, kp => kp.Id); List processList = clientContext.Web.Lists.GetByTitle("Process"); clientContext.Load(processList, p => p.Id); List subProcessList = clientContext.Web.Lists.GetByTitle("SubProcess"); clientContext.Load(subProcessList, sp => sp.Id); List regionList = clientContext.Web.Lists.GetByTitle("Region"); clientContext.Load(regionList, r => r.Id); List taskList = clientContext.Web.Lists.GetByTitle("Task"); clientContext.Load(taskList, t => t.Id); List geographyLevel1List = clientContext.Web.Lists.GetByTitle("GeographyLevel1"); clientContext.Load(geographyLevel1List, gl1 => gl1.Id); List geographyLevel2List = clientContext.Web.Lists.GetByTitle("GeographyLevel2"); clientContext.Load(geographyLevel2List, gl2 => gl2.Id); List issueList = clientContext.Web.Lists.GetByTitle("Issue"); clientContext.Load(issueList, i => i.Id); List currencyList = clientContext.Web.Lists.GetByTitle("Currency"); clientContext.Load(currencyList, c => c.Id); clientContext.ExecuteQuery(); string frequencyChoices = "<CHOICES>" + " <CHOICE>Annually</CHOICE>" + " <CHOICE>Biennially</CHOICE>" + " <CHOICE>Bi-Annually</CHOICE>" + " <CHOICE>Semi-Annually</CHOICE>" + " <CHOICE>Monthly</CHOICE>" + " <CHOICE>Quarterly</CHOICE>" + " <CHOICE>Quarterly</CHOICE>" + " <CHOICE>One-Time</CHOICE>" + " <CHOICE>N/A</CHOICE>" + " <CHOICE>Varies</CHOICE>" + " <CHOICE>Fees</CHOICE>" + " <CHOICE>Occasional</CHOICE>" + " <CHOICE>F2</CHOICE>" + "</CHOICES>"; string YearChoices = "<CHOICES>" + " <CHOICE>2010</CHOICE>" + " <CHOICE>2011</CHOICE>" + " <CHOICE>2012</CHOICE>" + " <CHOICE>2013</CHOICE>" + " <CHOICE>2014</CHOICE>" + " <CHOICE>2015</CHOICE>" + " <CHOICE>2016</CHOICE>" + " <CHOICE>2017</CHOICE>" + " <CHOICE>2018</CHOICE>" + " <CHOICE>2019</CHOICE>" + " <CHOICE>2020</CHOICE>" + "</CHOICES>"; string statusesChoices = "<CHOICES>" + " <CHOICE>Not Started</CHOICE>" + " <CHOICE>In Progress</CHOICE>" + " <CHOICE>Completed</CHOICE>" + "</CHOICES>"; string finalStatusChoices = "<CHOICES>" + " <CHOICE>Not Started</CHOICE>" + " <CHOICE>Pending Client Data</CHOICE>" + " <CHOICE>Client Data Received</CHOICE>" + " <CHOICE>In Preparation</CHOICE>" + " <CHOICE>In Review</CHOICE>" + " <CHOICE>Pending Approval</CHOICE>" + " <CHOICE>Pending EY Approval</CHOICE>" + " <CHOICE>Ready For Client</CHOICE>" + " <CHOICE>Pending Client Approval</CHOICE>" + " <CHOICE>Ready For Filing</CHOICE>" + " <CHOICE>Completed and not yet filed</CHOICE>" + " <CHOICE>Completed</CHOICE>" + "</CHOICES>"; string taskPeriodChoices = "<CHOICES>" + " <CHOICE>Q1</CHOICE>" + " <CHOICE>Q2</CHOICE>" + " <CHOICE>Q3</CHOICE>" + " <CHOICE>Q4</CHOICE>" + " <CHOICE>Annual</CHOICE>" + " <CHOICE>Monthly</CHOICE>" + " <CHOICE>January</CHOICE>" + " <CHOICE>February</CHOICE>" + " <CHOICE>March</CHOICE>" + " <CHOICE>April</CHOICE>" + " <CHOICE>May</CHOICE>" + " <CHOICE>June</CHOICE>" + " <CHOICE>July</CHOICE>" + " <CHOICE>August</CHOICE>" + " <CHOICE>September</CHOICE>" + " <CHOICE>October</CHOICE>" + " <CHOICE>November</CHOICE>" + " <CHOICE>December</CHOICE>" + " <CHOICE>Biennially</CHOICE>" + " <CHOICE>Semi-Annual 1</CHOICE>" + " <CHOICE>Semi-Annual 2</CHOICE>" + " <CHOICE>Bi-Monthly 1</CHOICE>" + " <CHOICE>Bi-Monthly 2</CHOICE>" + "</CHOICES>"; string issueStatusChoices = "<CHOICES>" + " <CHOICE>Active</CHOICE>" + " <CHOICE>Resolved</CHOICE>" + " <CHOICE>Closed</CHOICE>" + "</CHOICES>"; string priorityChoices = "<CHOICES>" + " <CHOICE>Critical</CHOICE>" + " <CHOICE>High</CHOICE>" + " <CHOICE>Medium</CHOICE>" + " <CHOICE>Low</CHOICE>" + "</CHOICES>"; string jurisdictionTypeChoices = "<CHOICES>" + " <CHOICE>City</CHOICE>" + " <CHOICE>Country</CHOICE>" + " <CHOICE>State\\Province</CHOICE>" + " <CHOICE>Municipality</CHOICE>" + "</CHOICES>"; string categoryChoices = "<CHOICES>" + "<CHOICE>Category 1</CHOICE>" + "<CHOICE>Category 2</CHOICE>" + "<CHOICE>Category 3</CHOICE>" + "</CHOICES>"; var listOfSiteColumnProperty = new List <SiteColumnProperty> { //Custom_Columns Group Site Column new SiteColumnProperty() { DisplayName = "Task Name", Name = "SC_TaskName", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Entity", Name = "SC_Entity", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = EntityList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "KeyProcess", Name = "SC_KeyProcess", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = keyProcessList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Process", Name = "SC_Process", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = processList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Sub Process", Name = "SC_SubProcess", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = subProcessList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Jurisdiction", Name = "SC_Jurisdiction", Format = "", Type = "Boolean", Group = "Custom_Columns", IsRequired = false, DefaultValue = "0" }, new SiteColumnProperty() { DisplayName = "Year", Name = "SC_Year", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = YearChoices }, new SiteColumnProperty() { DisplayName = "Geography Level1", Name = "SC_GeographyLevel1", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = geographyLevel1List.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Geography Level2", Name = "SC_GeographyLevel2", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = geographyLevel2List.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Region", Name = "SC_Region", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = regionList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "DueDate", Name = "SC_DueDate", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Period", Name = "SC_Period", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = taskPeriodChoices }, new SiteColumnProperty() { DisplayName = "Task Number", Name = "SC_TaskNumber", Format = "", Type = "Number", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Date Started", Name = "SC_DateStarted", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Extension Date", Name = "SC_ExtensionDate", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Final Status", Name = "SC_FinalStatus", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = finalStatusChoices }, new SiteColumnProperty() { DisplayName = "Assigned To", Name = "SC_AssignedTo", Format = "", Type = "User", Group = "Custom_Columns", IsRequired = false, UserSelectionMode = "PeopleAndGroups" }, new SiteColumnProperty() { DisplayName = "Approver", Name = "SC_Approver", Format = "", Type = "User", Group = "Custom_Columns", IsRequired = false, UserSelectionMode = "PeopleAndGroups" }, new SiteColumnProperty() { DisplayName = "Approver Status", Name = "SC_ApproverStatus", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = statusesChoices }, new SiteColumnProperty() { DisplayName = "Frequecny", Name = "SC_Frequency", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = frequencyChoices }, new SiteColumnProperty() { DisplayName = "Issue Status", Name = "SC_IssueStatus", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = issueStatusChoices }, new SiteColumnProperty() { DisplayName = "Priority", Name = "SC_Priority", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = priorityChoices }, new SiteColumnProperty() { DisplayName = "Description", Name = "SC_Descriptions", Format = "", Type = "Note", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Comments", Name = "SC_Comments", Format = "", Type = "Note", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Category", Name = "SC_Category", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = categoryChoices }, new SiteColumnProperty() { DisplayName = "RelatedTaskID", Name = "SC_RelatedTaskID", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "ID", List = taskList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Contact Name", Name = "SC_ContactName", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = true }, new SiteColumnProperty() { DisplayName = "Contact Role", Name = "SC_ContactRole", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = true }, new SiteColumnProperty() { DisplayName = "Contact Email", Name = "SC_ContactEmail", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = true }, new SiteColumnProperty() { DisplayName = "Contact Phone", Name = "SC_ContactPhone", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = true }, new SiteColumnProperty() { DisplayName = "Contact Photo", Name = "SC_ContactPhoto", Format = "Hyperlink", Type = "URL", Group = "Custom_Columns", IsRequired = true }, new SiteColumnProperty() { DisplayName = "File Name", Name = "SC_FileName", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Method Name", Name = "SC_MethodName", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Exception", Name = "SC_Exception", Format = "", Type = "Note", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "City", Name = "SC_City", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "State/Province", Name = "SC_State/Province", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Country", Name = "SC_Country", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = JurisdictionList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "JurisdictionType", Name = "SC_JurisdictionType", Format = "Dropdown", Type = "Choice", Group = "Custom_Columns", IsRequired = false, ChoicesDetails = jurisdictionTypeChoices }, new SiteColumnProperty() { DisplayName = "SubmittedBy", Name = "SC_SubmittedBy", Format = "", Type = "User", Group = "Custom_Columns", IsRequired = false, UserSelectionMode = "PeopleOnly" }, new SiteColumnProperty() { DisplayName = "Sort Order Number", Name = "SC_SortOrderNumber", Format = "", Type = "Number", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Start Date", Name = "SC_StartDate", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "End Date", Name = "SC_EndDate", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Logo URL", Name = "SC_LogoURL", Format = "Hyperlink", Type = "URL", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Country Code", Name = "SC_CountryCode", Format = "", Type = "Text", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Currency", Name = "SC_Currency", Format = "", Type = "Lookup", Group = "Custom_Columns", IsRequired = false, ShowField = "Title", List = currencyList.Id, WebId = oWeb.Id }, new SiteColumnProperty() { DisplayName = "Payment Date", Name = "SC_PaymentDate", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Payment Amount", Name = "SC_PaymentAmount", Format = "", Type = "Number", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "DownloadDate", Name = "SC_DownloadDate", Format = "DateOnly", Type = "DateTime", Group = "Custom_Columns", IsRequired = false }, new SiteColumnProperty() { DisplayName = "Downloaded By", Name = "SC_DownloadedBy", Format = "", Type = "User", Group = "Custom_Columns", IsRequired = false, UserSelectionMode = "PeopleOnly" }, }; ValidateAndCreate(clientContext, oWeb, listOfSiteColumnProperty); }