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);
}
}