//Generic method for all column types private static CSOMOperation AddField(this CSOMOperation operation, string name, FieldType type, string displayName = "", bool required = false, bool uniqueValues = false, string defaultValue = "", string group = "", int?maxLength = null, bool percentage = false, int decimals = 2, int?min = null, int?max = null, List <string> choices = null, ChoiceTypes choiceType = ChoiceTypes.Default, string lookupList = "", string lookupField = "") { operation.LogInfo($"Adding column {name}"); FieldCreationInformation fieldInformation = new FieldCreationInformation { InternalName = name, DisplayName = String.IsNullOrEmpty(displayName) ? name : displayName, FieldType = type, Required = required, UniqueValues = uniqueValues, Group = group, Default = defaultValue, Percentage = percentage, Decimals = decimals, Min = min, Max = max, Choices = choices, Format = choiceType, List = lookupList, ShowField = lookupField, MaxLegth = maxLength }; DecideFieldSource(operation).AddFieldAsXml(fieldInformation.ToXml(), true, AddFieldOptions.AddFieldInternalNameHint); return(operation); }
public static CSOMOperation ModifyColumn(this CSOMOperation operation, string columnName, FieldType?type = null, string displayName = null, bool?required = null, bool?uniqueValues = null) { operation.LogInfo($"Modifying column {columnName}"); var field = DecideFieldSource(operation).GetByInternalNameOrTitle(columnName); if (field == null) { if (type.HasValue) { field.TypeAsString = type.ToString(); } } if (!String.IsNullOrEmpty(displayName)) { field.Title = displayName; } if (required.HasValue) { field.Required = required.Value; } if (uniqueValues.HasValue) { field.EnforceUniqueValues = uniqueValues.Value; } field.UpdateAndPushChanges(true); return(operation); }
public static CSOMOperation CreateWeb(this CSOMOperation operation, string title, int?lcid, string url = "", string template = "") { operation.LogInfo($"Creating web {title}"); url = url.IsNotNullOrEmpty() ? url : operation.NormalizeUrl(title); Web rootWeb = operation.DecideWeb(); lcid = (int)((uint?)lcid ?? operation.DecideWeb().Language); operation.LogDebug($"Web creation information set to Title: {title}, Url: {url}, Lcid: {lcid}, Template: {template}"); WebCreationInformation webInformation = new WebCreationInformation { Title = title, Url = url, WebTemplate = template, Language = lcid.Value }; var web = rootWeb.Webs.Add(webInformation); operation.LoadWebWithDefaultRetrievals(web); operation.SetLevel(OperationLevels.Web, web); operation.ActionQueue.Enqueue(new DeferredAction { ClientObject = web, Action = DeferredActions.Load }); return(operation); }
public static CSOMOperation LoadWeb(this CSOMOperation operation, Guid id, params Expression <Func <Web, object> >[] retrievals) { operation.LogInfo($"Loading web with id: {id}"); Web web = operation.LastSite.OpenWebById(id); return(LoadWeb(operation, web, retrievals)); }
public static CSOMOperation DeleteColumn(this CSOMOperation operation, string columnName) { operation.LogInfo($"Removing column {columnName}"); var field = DecideFieldSource(operation).GetByInternalNameOrTitle(columnName); field.DeleteObject(); return(operation); }
public static CSOMOperation DeleteWeb(this CSOMOperation operation) { operation.LogInfo($"Deleting last selected web: {operation.LastWeb.Title}"); operation.ActionQueue.Enqueue(new DeferredAction { ClientObject = operation.LastWeb, Action = DeferredActions.Delete }); return(operation); }
public static CSOMOperation DeleteFolder(this CSOMOperation operation, string remotePath) { operation.LogInfo($"Deleting folder: {remotePath}"); var list = operation.LastList; var resourceFolderPath = ResourcePath.FromDecodedUrl(list.RootFolder.Name + "/" + remotePath); list.RootFolder.Folders.GetByPath(resourceFolderPath).DeleteObject(); return(operation); }
public static CSOMOperation DeleteList(this CSOMOperation operation, string name) { operation.LogInfo($"Deleting list {name}"); var list = operation.LoadedLists[name]; operation.ActionQueue.Enqueue(new DeferredAction { ClientObject = list, Action = DeferredActions.Delete }); return(operation); }
/// <summary> /// This method first loads all items valid for <paramref name="query"/> and then enqueue removal actions /// </summary> /// <param name="operation">Not context execution method</param> /// <param name="query"><see cref="CamlQuery"/> parameter used for list item selection</param> /// <returns></returns> public static CSOMOperation DeleteItems(this CSOMOperation operation, CamlQuery query) { operation.LogInfo("Deleting items"); operation.LogDebug($"Query:\n{query}"); var items = operation.LastList.GetItems(query); operation.Context.Load(items); operation.ActionQueue.Enqueue(new DeferredAction { ClientObject = items, Action = DeferredActions.Delete }); return(operation); }
public static CSOMOperation CreateFolder(this CSOMOperation operation, string remotePath, bool overwrite = true) { operation.LogInfo($"Creating folder: {remotePath}"); var list = operation.LastList; var resourceFolderPath = ResourcePath.FromDecodedUrl(list.RootFolder.Name + "/" + remotePath); var folder = list.RootFolder.Folders.AddUsingPath(resourceFolderPath, new FolderCollectionAddParameters { Overwrite = overwrite }); folder.Context.Load(folder); return(operation); }
public static WebTemplateCollection GetWebTemplates(this CSOMOperation operation, uint lcid, bool overrideCompatibilityLevel = false, Action <ClientContext, WebTemplateCollection> templatesLoader = null) { operation.LogInfo($"Getting web templates for LCID {lcid}"); var collection = operation.LastSite.GetWebTemplates(lcid, overrideCompatibilityLevel ? 1 : 0); if (templatesLoader != null) { templatesLoader(operation.Context, collection); } else { operation.Context.Load(collection); } operation.Execute(); return(collection); }
/// <summary> /// Get items from the last loaded list using standard <see cref="CamlQuery"/> /// </summary> /// <param name="operation">Beware! Context executing method</param> /// <param name="query">Query used in GetItems method</param> /// <param name="retrievals"></param> /// <returns>Loaded list items in standard CSOM <see cref="ListItemCollection"/></returns> public static ListItemCollection GetItems(this CSOMOperation operation, CamlQuery query, params Expression <Func <ListItem, object> >[] retrievals) { operation.LogInfo("Getting items"); operation.LogDebug($"Query:\n{query.ViewXml}"); var listItems = operation.LastList.GetItems(query); if (retrievals != null) { operation.Context.Load(listItems, collection => collection.Include(retrievals)); } else { operation.Context.Load(listItems); } operation.Execute(); return(listItems); }
public static CSOMOperation CreateList(this CSOMOperation operation, string name, string template = null) { operation.LogInfo($"Creating list {name}"); ListCreationInformation listInformation = new ListCreationInformation { Title = name, ListTemplate = String.IsNullOrEmpty(template) ? operation.LastWeb.ListTemplates.GetByName("Custom List") : operation.LastWeb.ListTemplates.GetByName(template) }; var list = operation.LastWeb.Lists.Add(listInformation); operation.LastWeb.Context.Load(list); operation.SetLevel(OperationLevels.List, list); operation.ActionQueue.Enqueue(new DeferredAction { ClientObject = list, Action = DeferredActions.Load }); return(operation); }