Как получить список, используя CSOM (лучшая практика)?

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/86144

  •  10-12-2019
  •  | 
  •  

Вопрос

Какой был бы полный код для лучшей практики, чтобы получить список, используя CSOM?

Пара соответствующих вопросов:

    .
  • Мы всегда должны сначала вернуть все списки, а затем запустить запрос LINQ, чтобы выбрать правильный?
  • Какая собственность мы должны использовать, чтобы получить список?Я хотел бы использовать имя URL (/ myList /) вместо заголовка или GUID, потому что заголовок (по крайней мере теоретически) должен быть меняющимся и GUID становится сложным между средами (Dev / Test / QA / ON-PEMPLISES / O365).Есть ли свойство для этого URL-адреса (без веб-URL)
  • будет подход быть самым быстрым в большинстве сценариев?

    Я бы также хотел бы иметь некоторые рассуждения позади предлагаемого решения.

Это было полезно?

Решение

As always it depends.

  • Getting the list by title will give you the best performance as the ListCollection.GetByTitle doesn't even require a trip to the server before you can use the list. But it has the downside that the user can easily change the title and make your code fail.

  • Getting the list by Url or Id will require you to retrieve these properties for all list which require a round trip to the server. Using the Url (relative) will work across sites, but the user has the possibility of moving the list which will then again break your code.

In cases where I can't trust the users not to change things they should leave alone and on the other hand I need to be able to have the code working as stable as possible across sites I've used the approach of:

  • storing Id and Url in a web.property (assume Guid.Empty and default url if nothing is stored)
  • retrieve Id and Url of all lists
  • if any Id match use that list (and update the property if the Url isn't right)
  • if no Id match by an Url does use that list and update Id
  • if no Id nor Url match then cry
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top