How to get a line from list by number using the webframe

zenfreak

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

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
Hi.
The link you posted shows some random ranges from the list and not by line number.

To get a line by number:

Код:
var myListName = project.Lists["ProjectListName"];
return myListName[5];
Above code will return 5 line off list. :-)
 
  • Спасибо
Реакции: zenfreak

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
12
Баллы
18
Simple and effective. Thank you!

Do you know why is it random1? Is there a random2 also ?
 

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
12
Баллы
18
Well .. not as effective as I thought. First, getting the item like this
Код:
return project.Lists["List 1"].GetItem("random1(1,12-15,35-end)");
will extract the list element straight from that list without the need to create an additional list myListName and, more important, will let me choose if I also want to remove that item or not

So I would still want to know how to get the 5th element from a list using the webframe method so I will be able to also remove that element.

What I am really trying to achieve is to loop through the whole list and if I find a string element whose length is less than 100, then assign that string to a variable and delete the element from list. The list is also linked to a file with the property of saving the change list to file activated so I assume that line will be also deleted from the file.
 

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
12
Баллы
18
Код:
var myListName = project.Lists["myAwesomeList"];
int countListElements=  myListName.Count();

for (int i = 0; i<countListElements; i++){
   
    int currentElementLength = myAwesomeList[i].Length;
    string currentElement =  project.Lists["myAwesomeList"].GetItem("random1(i)");
    project.SendInfoToLog(currentElement);
   
}
This code gives this error:
02:21:49 Perform the CSharp OwnCode Invalid format of the collection numbers. ElementsInCollection: 23. Path: random1(i)

If I replace random1(i) with random1(0) gives no error and spits the first element to the log, as it should. So how can I get an element by its position from myAwesomeList using the GetItem function so I can be able to also remove that element if necessary?
 

zenfreak

Client
Регистрация
21.08.2013
Сообщения
249
Благодарностей
12
Баллы
18
Found my answer.

This line should be
Код:
 string currentElement =  project.Lists["myAwesomeList"].GetItem(stringI, true);
where stringI is:
Код:
string stringI = i.ToString();
So GetItem expects a string value for the line number o_O
 

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