Example #1
0
        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);
        }
        //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 ModifyList(this CSOMOperation operation, Action <Microsoft.SharePoint.Client.List> changes)
        {
            changes(operation.LastList);
            operation.LastList.Update();

            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 AddNumberField(this CSOMOperation operation, string name, string displayName = "",
                                            bool required   = false, bool uniqueValues = false, string defaultValue = "", string group = "",
                                            bool percentage = false, int decimals      = 2, int?min = null, int?max = null)
 {
     return(operation.AddField(name, FieldType.Number, displayName, required, uniqueValues, defaultValue, group,
                               null, percentage, decimals, max, min));
 }
Example #6
0
        public static CSOMOperation LoadList(this CSOMOperation operation, string name, Action <ClientContext, Microsoft.SharePoint.Client.List> listLoader = null)
        {
            operation.LogDebug($"Loading list {name}");

            var web  = operation.DecideWeb();
            var list = web.Lists.GetByTitle(name);

            operation.LoadListRequired(list);

            if (listLoader != null)
            {
                listLoader(operation.Context, list);
            }
            else
            {
                operation.Context.Load(list);
            }

            operation.SetLevel(OperationLevels.List, list);
            operation.ActionQueue.Enqueue(new DeferredAction {
                ClientObject = operation.LastList, Action = DeferredActions.Load
            });

            return(operation);
        }
Example #7
0
        public static CSOMOperation DeleteItem(this CSOMOperation operation, int itemId)
        {
            operation.LastList
            .GetItemById(itemId)
            .DeleteObject();

            return(operation);
        }
Example #8
0
        /// <summary>
        /// Remove all items from list
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        public static CSOMOperation DeleteItems(this CSOMOperation operation)
        {
            var caml = CamlQuery.CreateAllItemsQuery();

            operation.DeleteItems(caml);

            return(operation);
        }
Example #9
0
        public static CSOMOperation CreateTermGroup(this CSOMOperation operation, string name, Guid?guid = null)
        {
            var op = operation.TaxonomyOperation;

            op.LastTermGroup = op.LastTermStore.CreateGroup(name, guid ?? Guid.NewGuid());

            return(operation);
        }
Example #10
0
        public static CSOMOperation CreateTermSet(this CSOMOperation operation, string name, Guid?guid = null, int lcid = 1033)
        {
            var op = operation.TaxonomyOperation;

            op.LastTermSet = op.LastTermGroup.CreateTermSet(name, guid ?? Guid.NewGuid(), lcid);

            return(operation);
        }
Example #11
0
        public static CSOMOperation OpenTaxonomySession(this CSOMOperation operation)
        {
            EnsureTaxonomyOperation(operation);

            operation.TaxonomyOperation.Session = TaxonomySession.GetTaxonomySession(operation.Context);
            operation.Context.Load(operation.TaxonomyOperation.Session);

            return(operation);
        }
Example #12
0
        /// <summary>
        /// Load a term group from current <see cref="TaxonomyOperation.LastTermStore"/> by given <paramref name="guid"/> parameter.
        /// <para>This method does not add loaded term group in <see cref="TaxonomyOperation.LoadedTermGroups"/>.
        /// See Remarks section!</para>
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="guid">Id of the term group</param>
        /// <remarks>This method does not add loaded group into <see cref="TaxonomyOperation.LoadedTermGroups"/> because the name is not available yet</remarks>
        /// <returns></returns>
        public static CSOMOperation LoadTermGroup(this CSOMOperation operation, Guid guid, params Expression <Func <TermGroup, object> >[] retrievals)
        {
            var op = operation.TaxonomyOperation;

            op.LastTermGroup = op.LastTermStore.Groups.GetById(guid);
            operation.Load(op.LastTermGroup, retrievals.Length == 0 ? DefaultRetrievals.TermGroup : retrievals);

            return(operation);
        }
Example #13
0
        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));
        }
Example #14
0
        public static CSOMOperation LoadWebByUrl(this CSOMOperation operation, string url,
                                                 params Expression <Func <Web, object> >[] retrievals)
        {
            operation.LogDebug($"Loading web with url: {url}");

            var web = operation.LastSite.OpenWebUsingPath(ResourcePath.FromDecodedUrl(url));

            return(LoadWeb(operation, web, retrievals));
        }
Example #15
0
        public static CSOMOperation LoadWeb(this CSOMOperation operation, string name,
                                            params Expression <Func <Web, object> >[] retrievals)
        {
            operation.LogDebug($"Loading web");

            var web = operation.LastSite.OpenWeb(name);

            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);
        }
Example #17
0
        public static CSOMOperation DeleteItems(this CSOMOperation operation, string queryString)
        {
            var caml = new CamlQuery {
                ViewXml = $"<View>{queryString}</View>"
            };

            operation.DeleteItems(caml);

            return(operation);
        }
Example #18
0
        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);
        }
Example #19
0
        public static CSOMOperation GetWebTemplates(this CSOMOperation operation, uint?lcid = null, int?compatibilityLevel = null)
        {
            lcid = lcid ?? operation.DefaultLcid;
            compatibilityLevel = compatibilityLevel ?? operation.DefaultCompatibilityLevel;

            var templates = operation.LastSite.GetWebTemplates(lcid.Value, compatibilityLevel.Value);

            operation.Load(templates, CSOMOperation.DefaultRetrievals.WebTemplateCollection);
            return(operation);
        }
Example #20
0
        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);
        }
Example #21
0
        public static ListTemplateCollection GetListTemplates(this CSOMOperation operation, params Expression <Func <ListTemplateCollection, object> >[] retrievals)
        {
            var templates = operation.LastSite.GetCustomListTemplates(operation.DecideWeb());

            operation.Context.Load(templates, retrievals.Length > 0
                                        ? retrievals
                                        : CSOMOperation.DefaultRetrievals.ListTemplateCollection);

            operation.Execute();

            return(templates);
        }
Example #22
0
        /// <summary>
        /// Get Item using CamlQuery
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="query"></param>
        /// <param name="retrievals"></param>
        /// <returns></returns>
        public static ListItem GetItem(this CSOMOperation operation, CamlQuery query)
        {
            ListItemCollection items = operation
                                       .LastList
                                       .GetItems(query);

            ListItem item = items.FirstOrDefault();

            operation.Load(item);

            return(item);
        }
        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);
        }
Example #24
0
        /// <summary>
        /// Get Item by id
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="itemId"></param>
        /// <param name="retrievals"></param>
        /// <returns></returns>
        public static ListItem GetItem(this CSOMOperation operation, int itemId, params Expression <Func <ListItem, object> >[] retrievals)
        {
            ListItem item = operation.LastList.GetItemById(itemId);

            operation
            .Load(item, retrievals.Length > 0
                                                                                ? retrievals
                                                                                : CSOMOperation.DefaultRetrievals.ListItem)
            .Execute();

            return(item);
        }
Example #25
0
        public static CSOMOperation SelectList(this CSOMOperation operation, string name)
        {
            if (operation.LoadedLists.ContainsKey(name))
            {
                operation.SetLevel(OperationLevels.List, operation.LoadedLists[name]);
            }
            else
            {
                throw new ArgumentException($"List ${name} doesn't exist");
            }

            return(operation);
        }
        //todo logging
        public static CSOMOperation LoadContentTypes(this CSOMOperation operation, params Expression <Func <Microsoft.SharePoint.Client.ContentType, object> >[] keysToLoad)
        {
            throw new NotImplementedException();

            var contentTypes = DecideContentTypes(operation);

            if (contentTypes != null)
            {
                operation.Context.Load(contentTypes, ct => ct.Include(type => type.Fields, type => type.FieldLinks, type => type.Name), ct => ct.Include(keysToLoad));
            }

            return(operation);
        }
        public static CSOMOperation SelectContentType(this CSOMOperation operation, string name)
        {
            throw new NotImplementedException();

            var contentTypes = DecideContentTypes(operation);

            if (contentTypes != null)
            {
                operation.SetLevel(OperationLevels.ContentType, contentTypes.First(ct => ct.Name.Equals(name)));
            }

            return(operation);
        }
Example #28
0
        /// <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);
        }
Example #29
0
        private static void GetAndDeleteItem()
        {
            CSOMOperation op = SiteUrl
                               .Create(logger)
                               .SetOnlineCredentials(ClientSecrets.Username, ClientSecrets.Password)
                               .Execute();

            op.LoadList("Documents")
            .Execute();

            ListItem item = op.GetItem(1);

            ListItemCollection items = op.GetItems(x => x.Id, x => x.DisplayName);
        }
Example #30
0
        public static CSOMOperation SelectTermGroup(this CSOMOperation operation, string name)
        {
            var op  = operation.TaxonomyOperation;
            var key = name.ToLower();

            if (!op.LoadedTermGroups.ContainsKey(key))
            {
                throw new ArgumentOutOfRangeException(nameof(name), $"Could not find term group with name {key} in the already loaded groups.");
            }

            op.LastTermGroup = op.LoadedTermGroups[key];

            return(operation);
        }