Get Random List Items Using GetItems

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
11
Баллы
18
I would like to be able to get a random number of items from my list.

Код:
return string.Join(";", project.Lists["List 1"].GetItems("random20(1,12-15,35-end)"));
Following the documentation example, I would like to be able to replace 20 with another random value generated like this:

Код:
Random rnd = new Random();
int randomListValues = rnd.Next(1,7);
How can I replace the 20 from random20 with my randomListValues variable?

Obviously doing this does not work:

Код:
return string.Join(";", project.Lists["List 1"].GetItems("randomrandomListValues(1,12-15,35-end)"));
Replacing the range values (1,12-15,35-end) with my custom would also be helpfull
 

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
11
Баллы
18
Still needing this ...
 

Dimionix

Moderator
Регистрация
09.04.2011
Сообщения
3 068
Благодарностей
3 100
Баллы
113
C#:
Random rnd = new Random();
string randomListValues = rnd.Next(1, 7).ToString();
return string.Join(";", project.Lists["List 1"].GetItems("random" + randomListValues + "(1,12-15,35-end)"));
Replacing the range values (1,12-15,35-end) with my custom would also be helpfull
C#:
Random rnd = new Random();
string randomListValues = rnd.Next(1, 7).ToString();
string rangeValues = "1,12-15,35-end";
return string.Join(";", project.Lists["List 1"].GetItems("random" + randomListValues + "(" + rangeValues + ")"));
 
  • Спасибо
Реакции: zenfreak

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
11
Баллы
18
Thank you for taking the time to provide this answer. When I look at it now it makes sense :-)
 

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
11
Баллы
18
How can I get the first 100 elements from a list using GetItems?

No random and no rangevalues, just get the first 100 elements while also removing them
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)