Example #1
0
        public static void GetListItemByBatch()
        {
            CamlQuery camlQuery = new CamlQuery();

            //CamlQuery extension for LisThreshold limit

            //Set View Scope for the Query
            camlQuery.SetViewAttribute(QueryScope.RecursiveAll);

            //Set Viewfields as String array
            //camlQuery.SetViewFields(new string[] { "ID", "Title"});

            //Or Set the ViewFields xml
            camlQuery.SetViewFields(@"<FieldRef Name='ID'/><FieldRef Name='Title'/>");

            //Override the QueryThrottle Mode for avoiding ListViewThreshold exception
            camlQuery.SetQueryThrottleMode(QueryThrottleMode.Override);

            //If Query has filter, column which is Indexed can be used Override in Orderby
            //camlQuery.SetOrderByIndexField();

            //Use OrderBy ID field if Query doesn't have filter with indexed column
            camlQuery.SetOrderByIDField();

            //Set Query condition
            //camlQuery.SetQuery("<Eq><FieldRef Name='IndexedField' /><Value Type='Text'>value</Value></Eq>");

            //Set RowLimit
            camlQuery.SetQueryRowlimit(3000);

            using (ClientContext context = new ClientContext("SiteUrl"))
            {
                ContentIterator contentIterator = new ContentIterator(context);

                try
                {
                    contentIterator.ProcessListItem("ListName", camlQuery,
                                                    ProcessItem,
                                                    delegate(ListItem item, System.Exception ex)
                    {
                        return(true);
                    });

                    Console.WriteLine("Total :" + totalCount);
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadKey();
                }
            }
        }
Example #2
0
        public static void GetListItemsByBatch()
        {
            CamlQuery camlQuery = new CamlQuery();

            //CamlQuery extension for LisThreshold limit

            //Set View Scope for the Query
            camlQuery.SetViewAttribute(QueryScope.RecursiveAll);

            //Set Viewfields as String array
            //camlQuery.SetViewFields(new string[] { "ID", "Title"});

            //Or Set the ViewFields xml
            camlQuery.SetViewFields(@"<FieldRef Name='ID'/><FieldRef Name='Title'/>");

            //Override the QueryThrottle Mode for avoiding ListViewThreshold exception
           camlQuery.SetQueryThrottleMode(QueryThrottleMode.Override);

            //If Query has filter, column which is Indexed can be used Override in Orderby
            //camlQuery.SetOrderByIndexField();

            //Use OrderBy ID field if Query doesn't have filter with indexed column
            camlQuery.SetOrderByIDField();

            //Set Query condition
            //camlQuery.SetQuery("<Eq><FieldRef Name='IndexedField' /><Value Type='Text'>value</Value></Eq>");

            //Set RowLimit
            camlQuery.SetQueryRowlimit(3000);

            using (ClientContext context = new ClientContext("SiteUrl"))
            {
                ContentIterator contentIterator = new ContentIterator(context);

                try
                {
                    contentIterator.ProcessListItems("ListName", camlQuery,
                    ProcessItems,
                    delegate(ListItemCollection items, System.Exception ex)
                    {
                        return true;
                    });

                    Console.WriteLine("Total :" + totalCount);
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadKey();
                }
            }
        }
        public static void ReadFormLibUsingAppOnlyAndCredentials(PeoplePickerListsInput formLib, ref List<PeoplePickerListOutput> lstPeoplepickeroutput)
        {
            if (formLib == null)
                return;

            webUrl = formLib.WebUrl;
            listName = formLib.ListName;

            Logger.LogInfoMessage(String.Format("Processing PeoplePicker Form Library [{0}] of Web [{1}] ...", listName, webUrl), true);

            CamlQuery camlQuery = new CamlQuery();
            //Set View Scope for the Query
            camlQuery.SetViewAttribute(QueryScope.RecursiveAll);
            //Or Set the ViewFields xml
            //camlQuery.SetViewFields(@"<FieldRef Name='ID'/><FieldRef Name='Title'/>");
            //Override the QueryThrottle Mode for avoiding ListViewThreshold exception
            camlQuery.SetQueryThrottleMode(QueryThrottleMode.Override);
            //Use OrderBy ID field if Query doesn't have filter with indexed column
            camlQuery.SetOrderByIDField();
            //Set RowLimit
            camlQuery.SetQueryRowlimit(Convert.ToUInt32(ConfigurationManager.AppSettings["CamlQueryRowLimit"]));
            PeoplePickerListOutput peoplePickerOutput = new PeoplePickerListOutput();
            peoplePickerOutput.WebUrl = webUrl;
            peoplePickerOutput.ListName = formLib.ListName;
            try
            {
                using (ClientContext userContext = Helper.CreateClientContextBasedOnAuthMode(Program.UseAppModel, Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, webUrl))
                {
                    List list = userContext.Web.Lists.GetByTitle(listName);
                    userContext.Load(list);
                    userContext.Load(list.EventReceivers);
                    userContext.Load(list.WorkflowAssociations);
                    userContext.ExecuteQuery();

                    bool updateXmlIfEventReceiversNotFound = true;
                    bool updateXmlIfWorkflowsNotFound = true;

                    if (list.EventReceivers.Count > 0)
                    {
                        if (ConfigurationManager.AppSettings["UpdateUserInfoEvenIfEventReceiversEnabled"].ToString().Equals("No"))
                        {
                            updateXmlIfEventReceiversNotFound = true;
                            Logger.LogInfoMessage(String.Format("EventReceivers are associated with List [{0}] of Web [{1}] and permission is not given to update user info", listName, webUrl), true);
                        }
                    }

                    if (list.WorkflowAssociations.Count > 0)
                    {
                        if (ConfigurationManager.AppSettings["UpdateUserInfoEvenIfWorkflowsEnabled"].ToString().Equals("No"))
                        {
                            updateXmlIfWorkflowsNotFound = true;
                            Logger.LogInfoMessage(String.Format("Workflows are associated with List [{0}] of Web [{1}] and permission is not given to update user info", listName, webUrl), true);
                        }
                    }

                    if (updateXmlIfEventReceiversNotFound && updateXmlIfWorkflowsNotFound)
                    {
                        // TODO: uncomment below lines to switch read-only property
                        //PeoplePickerEdiorModified modified = new PeoplePickerEdiorModified();
                        //UpdateEditorAndModifiedFieldsProperty(userContext, list, listName, ref modified, false);

                        ContentIterator contentIterator = new ContentIterator(userContext);
                        try
                        {

                            contentIterator.ProcessListItem(listName, camlQuery,
                            ProcessItem, ref lstPeoplepickeroutput,
                            delegate(ListItem item, System.Exception ex)
                            {
                                return true;
                            });

                            Logger.LogInfoMessage("Total :" + totalCount, true);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogErrorMessage(ex.Message);
                        }

                        // TODO: uncomment below lines to switch read-only property
                        //if (modified.isEditorfieldModified || modified.isModifiedFieldModified)
                        //{
                        //    UpdateEditorAndModifiedFieldsProperty(userContext, list, listName, ref modified, true);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("ReadFormLibUsingAppOnlyAndCredentials() failed for PeroplePicker InfoPath Library [{0}] of Web [{1}]: Error={2}", listName, webUrl, ex.Message), true);
                peoplePickerOutput.Status = Constants.ErrorStatus;
                peoplePickerOutput.ErrorDetails = ex.Message;
                lstPeoplepickeroutput.Add(peoplePickerOutput);
            }
        }
Example #4
0
        public static void ReadFormLibUsingAppOnlyAndCredentials(PeoplePickerListsInput formLib, ref List <PeoplePickerListOutput> lstPeoplepickeroutput)
        {
            if (formLib == null)
            {
                return;
            }

            webUrl   = formLib.WebUrl;
            listName = formLib.ListName;


            Logger.LogInfoMessage(String.Format("Processing PeoplePicker Form Library [{0}] of Web [{1}] ...", listName, webUrl), true);

            CamlQuery camlQuery = new CamlQuery();

            //Set View Scope for the Query
            camlQuery.SetViewAttribute(QueryScope.RecursiveAll);
            //Or Set the ViewFields xml
            //camlQuery.SetViewFields(@"<FieldRef Name='ID'/><FieldRef Name='Title'/>");
            //Override the QueryThrottle Mode for avoiding ListViewThreshold exception
            camlQuery.SetQueryThrottleMode(QueryThrottleMode.Override);
            //Use OrderBy ID field if Query doesn't have filter with indexed column
            camlQuery.SetOrderByIDField();
            //Set RowLimit
            camlQuery.SetQueryRowlimit(Convert.ToUInt32(ConfigurationManager.AppSettings["CamlQueryRowLimit"]));
            PeoplePickerListOutput peoplePickerOutput = new PeoplePickerListOutput();

            peoplePickerOutput.WebUrl   = webUrl;
            peoplePickerOutput.ListName = formLib.ListName;
            try
            {
                using (ClientContext userContext = Helper.CreateClientContextBasedOnAuthMode(Program.UseAppModel, Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, webUrl))
                {
                    List list = userContext.Web.Lists.GetByTitle(listName);
                    userContext.Load(list);
                    userContext.Load(list.EventReceivers);
                    userContext.Load(list.WorkflowAssociations);
                    userContext.ExecuteQuery();

                    bool updateXmlIfEventReceiversNotFound = true;
                    bool updateXmlIfWorkflowsNotFound      = true;

                    if (list.EventReceivers.Count > 0)
                    {
                        if (ConfigurationManager.AppSettings["UpdateUserInfoEvenIfEventReceiversEnabled"].ToString().Equals("No"))
                        {
                            updateXmlIfEventReceiversNotFound = true;
                            Logger.LogInfoMessage(String.Format("EventReceivers are associated with List [{0}] of Web [{1}] and permission is not given to update user info", listName, webUrl), true);
                        }
                    }

                    if (list.WorkflowAssociations.Count > 0)
                    {
                        if (ConfigurationManager.AppSettings["UpdateUserInfoEvenIfWorkflowsEnabled"].ToString().Equals("No"))
                        {
                            updateXmlIfWorkflowsNotFound = true;
                            Logger.LogInfoMessage(String.Format("Workflows are associated with List [{0}] of Web [{1}] and permission is not given to update user info", listName, webUrl), true);
                        }
                    }

                    if (updateXmlIfEventReceiversNotFound && updateXmlIfWorkflowsNotFound)
                    {
                        // TODO: uncomment below lines to switch read-only property
                        //PeoplePickerEdiorModified modified = new PeoplePickerEdiorModified();
                        //UpdateEditorAndModifiedFieldsProperty(userContext, list, listName, ref modified, false);

                        ContentIterator contentIterator = new ContentIterator(userContext);
                        try
                        {
                            contentIterator.ProcessListItem(listName, camlQuery,
                                                            ProcessItem, ref lstPeoplepickeroutput,
                                                            delegate(ListItem item, System.Exception ex)
                            {
                                return(true);
                            });

                            Logger.LogInfoMessage("Total :" + totalCount, true);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogErrorMessage(ex.Message);
                        }

                        // TODO: uncomment below lines to switch read-only property
                        //if (modified.isEditorfieldModified || modified.isModifiedFieldModified)
                        //{
                        //    UpdateEditorAndModifiedFieldsProperty(userContext, list, listName, ref modified, true);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("ReadFormLibUsingAppOnlyAndCredentials() failed for PeroplePicker InfoPath Library [{0}] of Web [{1}]: Error={2}", listName, webUrl, ex.Message), true);
                peoplePickerOutput.Status       = Constants.ErrorStatus;
                peoplePickerOutput.ErrorDetails = ex.Message;
                lstPeoplepickeroutput.Add(peoplePickerOutput);
            }
        }
        public static void ReadFormLibUsingAppOnlyAndCredentials(PeoplePickerListsInput formLib, ref List <PeoplePickerListOutput> lstPeoplepickeroutput)
        {
            if (formLib == null)
            {
                return;
            }

            webUrl   = formLib.WebUrl;
            listName = formLib.ListName;


            Logger.LogInfoMessage(String.Format("Processing PeoplePicker InfoPath Form Library [{0}] of Web [{1}] ...", listName, webUrl), true);

            CamlQuery camlQuery = new CamlQuery();

            //Set View Scope for the Query
            camlQuery.SetViewAttribute(QueryScope.RecursiveAll);
            //Or Set the ViewFields xml
            //camlQuery.SetViewFields(@"<FieldRef Name='ID'/><FieldRef Name='Title'/>");
            //Override the QueryThrottle Mode for avoiding ListViewThreshold exception
            camlQuery.SetQueryThrottleMode(QueryThrottleMode.Override);
            //Use OrderBy ID field if Query doesn't have filter with indexed column
            camlQuery.SetOrderByIDField();
            //Set RowLimit
            camlQuery.SetQueryRowlimit(Convert.ToUInt32(ConfigurationManager.AppSettings["CamlQueryRowLimit"]));
            PeoplePickerListOutput peoplePickerOutput = new PeoplePickerListOutput();

            peoplePickerOutput.WebUrl   = webUrl;
            peoplePickerOutput.ListName = formLib.ListName;
            try
            {
                using (ClientContext userContext = Helper.CreateClientContextBasedOnAuthMode(Program.UseAppModel, Program.AdminDomain, Program.AdminUsername, Program.AdminPassword, webUrl))
                {
                    List list = userContext.Web.Lists.GetByTitle(listName);
                    userContext.Load(list);
                    userContext.Load(list.EventReceivers);
                    userContext.Load(list.WorkflowAssociations);
                    userContext.ExecuteQueryRetry();

                    // By default, we will process the specified library unless we find that it has event receiver registrations or workflow associations.
                    // We are about to update the files of this library and we do not want to cause side effects that might arise from triggering a event receiver or workflow.
                    bool processTheLibrary = true;

                    if (list.EventReceivers.Count > 0)
                    {
                        // We found some event receivers on the library.  Consult the app setting to determine if we should still process the library.
                        if (String.Equals(ConfigurationManager.AppSettings["UpdateUserInfoEvenIfEventReceiversEnabled"].ToString(), "Yes", StringComparison.InvariantCultureIgnoreCase) == true)
                        {
                            Logger.LogWarningMessage(String.Format("[{0}] EventReceivers are associated with List [{1}] of Web [{2}]; event receivers might be executed", list.EventReceivers.Count, listName, webUrl), true);
                        }
                        else
                        {
                            // The admin has not configured this utility to process libraries that have event receivers
                            processTheLibrary = false;
                            Logger.LogWarningMessage(String.Format("[{0}] EventReceivers are associated with List [{1}] of Web [{2}]; skipping the list per the AppSetting", list.EventReceivers.Count, listName, webUrl), true);
                        }
                    }

                    if (list.WorkflowAssociations.Count > 0)
                    {
                        // We found some workflow associations on the library.  Consult the app setting to determine if we should still process the library.
                        if (String.Equals(ConfigurationManager.AppSettings["UpdateUserInfoEvenIfWorkflowsEnabled"].ToString(), "Yes", StringComparison.InvariantCultureIgnoreCase) == true)
                        {
                            Logger.LogWarningMessage(String.Format("[{0}] Workflows are associated with List [{1}] of Web [{2}]; workflows might be started", list.WorkflowAssociations.Count, listName, webUrl), true);
                        }
                        else
                        {
                            // The admin has not configured this utility to process libraries that have workflow associations
                            processTheLibrary = false;
                            Logger.LogWarningMessage(String.Format("[{0}] Workflows are associated with List [{1}] of Web [{2}]; skipping the list per the AppSetting", list.WorkflowAssociations.Count, listName, webUrl), true);
                        }
                    }

                    // Process the library if it is still OK to do so.
                    if (processTheLibrary)
                    {
                        // TODO: uncomment below lines to switch read-only property
                        //PeoplePickerEdiorModified modified = new PeoplePickerEdiorModified();
                        //UpdateEditorAndModifiedFieldsProperty(userContext, list, listName, ref modified, false);

                        ContentIterator contentIterator = new ContentIterator(userContext);
                        try
                        {
                            contentIterator.ProcessListItem(listName, camlQuery, ProcessItem, ref lstPeoplepickeroutput,
                                                            delegate(ListItem item, System.Exception ex)
                            {
                                return(true);
                            });

                            Logger.LogInfoMessage(String.Format("[{0}] InfoPath Form files processed for List [{1}] of Web [{2}]", totalCount, listName, webUrl), true);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogErrorMessage(ex.Message);
                        }

                        // TODO: uncomment below lines to switch read-only property
                        //if (modified.isEditorfieldModified || modified.isModifiedFieldModified)
                        //{
                        //    UpdateEditorAndModifiedFieldsProperty(userContext, list, listName, ref modified, true);
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogErrorMessage(String.Format("ReadFormLibUsingAppOnlyAndCredentials() failed for PeroplePicker InfoPath Library [{0}] of Web [{1}]: Error={2}", listName, webUrl, ex.Message), true);
                peoplePickerOutput.Status       = Constants.ErrorStatus;
                peoplePickerOutput.ErrorDetails = ex.Message;
                lstPeoplepickeroutput.Add(peoplePickerOutput);
            }
        }