public async Task <List <KeyValuePair <string, string> > > GetLookupItems(Model.FieldLookup lookup) { if (lookup.LookupWebId == Guid.Empty || string.IsNullOrEmpty(lookup.LookupList)) { return(null); } using (var context = CreateContext(lookup.List.Web.Url)) { var lookupField = string.IsNullOrEmpty(lookup.LookupField) ? "Title" : lookup.LookupField; var caml = $@" <Query> <Where /> </Query>"; ListItemCollection pageItems = null; var pageSize = 2000; var items = new List <KeyValuePair <string, string> >(); var web = context.Site.OpenWebById(lookup.LookupWebId); var list = web.Lists.GetById(Guid.Parse(lookup.LookupList)); do { var rowLimit = $"<RowLimit>{pageSize}</RowLimit>"; var listQuery = new CamlQuery { ViewXml = $"<View Scope='RecursiveAll'>{caml}{rowLimit}</View>", ListItemCollectionPosition = pageItems?.ListItemCollectionPosition }; pageItems = list.GetItems(listQuery); context.Load(pageItems, elements => elements.Include( i => i.Id, i => i[lookupField] ), elements => elements.ListItemCollectionPosition); await Task.Factory.StartNew(() => context.ExecuteQuery()); items.AddRange( pageItems .Cast <ListItem>() .Select(i => new KeyValuePair <string, string>( i.Id.ToString(), i[lookupField] != null ? i[lookupField].ToString() : string.Empty ) ) ); }while (pageItems?.ListItemCollectionPosition != null); return(items .OrderBy(i => i.Value) .ToList()); } }
private Model.Field CreateField(SPField listField) { Model.Field field; switch (listField.Type) { case SPFieldType.Choice: field = new Model.FieldChoice { Choices = ((SPFieldChoice)listField).Choices.Cast <string>().ToList() }; break; case SPFieldType.MultiChoice: field = new Model.FieldChoice { Choices = ((SPFieldMultiChoice)listField).Choices.Cast <string>().ToList() }; break; case SPFieldType.DateTime: field = new Model.FieldDateTime { DateOnly = ((SPFieldDateTime)listField).DisplayFormat == SPDateTimeFieldFormatType.DateOnly }; break; case SPFieldType.Lookup: field = new Model.FieldLookup { AllowMultivalue = ((SPFieldLookup)listField).AllowMultipleValues }; break; default: field = new Model.Field(); break; } field.Id = listField.Id; field.IsHidden = listField.Hidden; field.IsReadonly = listField.ReadOnlyField; field.Title = listField.Title; field.InternalName = listField.InternalName; field.Group = listField.Group; field.Type = (Model.FieldType)listField.Type; return(field); }
private Model.Field CreateField(Field listField) { Model.Field field; switch (listField.FieldTypeKind) { case FieldType.Choice: field = new Model.FieldChoice { Choices = ((Client.FieldChoice)listField).Choices }; break; case FieldType.MultiChoice: field = new Model.FieldChoice { Choices = ((Client.FieldMultiChoice)listField).Choices }; break; case FieldType.DateTime: field = new Model.FieldDateTime { DateOnly = ((Client.FieldDateTime)listField).DisplayFormat == DateTimeFieldFormatType.DateOnly }; break; case FieldType.Lookup: field = new Model.FieldLookup { AllowMultivalue = ((Client.FieldLookup)listField).AllowMultipleValues }; break; case FieldType.User: field = new Model.FieldLookup { AllowMultivalue = ((Client.FieldUser)listField).AllowMultipleValues }; break; case FieldType.Invalid: switch (listField.TypeAsString) { case "TaxonomyFieldType": field = new Model.FieldTaxonomy {AllowMultivalue = false, Type = Model.FieldType.Taxonomy, IsReadonly = true}; break; case "TaxonomyFieldTypeMulti": field = new Model.FieldTaxonomy { AllowMultivalue = true, Type = Model.FieldType.Taxonomy, IsReadonly = true}; break; default: field = new Model.Field(); break; } break; default: field = new Model.Field(); break; } field.Id = listField.Id; field.IsHidden = listField.Hidden; field.IsReadonly |= listField.ReadOnlyField; field.Title = listField.Title; field.InternalName = listField.InternalName; field.Group = listField.Group; if( field.Type == 0 ) field.Type = (Model.FieldType)listField.FieldTypeKind; return field; }
private Model.Field CreateField(SPField listField) { Model.Field field; switch (listField.Type) { case SPFieldType.Choice: field = new Model.FieldChoice { Choices = ((SPFieldChoice)listField).Choices.Cast<string>().ToList() }; break; case SPFieldType.MultiChoice: field = new Model.FieldChoice { Choices = ((SPFieldMultiChoice)listField).Choices.Cast<string>().ToList() }; break; case SPFieldType.DateTime: field = new Model.FieldDateTime { DateOnly = ((SPFieldDateTime)listField).DisplayFormat == SPDateTimeFieldFormatType.DateOnly }; break; case SPFieldType.Lookup: field = new Model.FieldLookup {AllowMultivalue = ((SPFieldLookup)listField).AllowMultipleValues}; break; default: field = new Model.Field(); break; } field.Id = listField.Id; field.IsHidden = listField.Hidden; field.IsReadonly = listField.ReadOnlyField; field.Title = listField.Title; field.InternalName = listField.InternalName; field.Group = listField.Group; field.Type = (Model.FieldType)listField.Type; return field; }
private Model.Field CreateField(Field listField) { Model.Field field; switch (listField.FieldTypeKind) { case FieldType.Choice: field = new Model.FieldChoice { Choices = ((Client.FieldChoice)listField).Choices }; break; case FieldType.MultiChoice: field = new Model.FieldChoice { Choices = ((Client.FieldMultiChoice)listField).Choices }; break; case FieldType.DateTime: field = new Model.FieldDateTime { DateOnly = ((Client.FieldDateTime)listField).DisplayFormat == DateTimeFieldFormatType.DateOnly }; break; case FieldType.Lookup: field = new Model.FieldLookup { AllowMultivalue = ((Client.FieldLookup)listField).AllowMultipleValues, LookupField = ((Client.FieldLookup)listField).LookupField, LookupList = ((Client.FieldLookup)listField).LookupList, LookupWebId = ((Client.FieldLookup)listField).LookupWebId }; break; case FieldType.User: field = new Model.FieldLookup { AllowMultivalue = ((Client.FieldUser)listField).AllowMultipleValues, LookupField = ((Client.FieldLookup)listField).LookupField, LookupList = ((Client.FieldUser)listField).LookupList, LookupWebId = ((Client.FieldUser)listField).LookupWebId }; break; case FieldType.Invalid: switch (listField.TypeAsString) { case "TaxonomyFieldType": field = new Model.FieldTaxonomy { AllowMultivalue = false, Type = Model.FieldType.Taxonomy, IsReadonly = true }; break; case "TaxonomyFieldTypeMulti": field = new Model.FieldTaxonomy { AllowMultivalue = true, Type = Model.FieldType.Taxonomy, IsReadonly = true }; break; default: field = new Model.Field(); break; } break; default: field = new Model.Field(); break; } field.Id = listField.Id; field.IsHidden = listField.Hidden; field.IsReadonly |= listField.ReadOnlyField; field.Title = listField.Title; field.InternalName = listField.InternalName; field.Group = listField.Group; if (field.Type == 0) { field.Type = (Model.FieldType)listField.FieldTypeKind; } return(field); }