Frage

Was wäre der vollständige Code für eine Best-Practice, um eine Liste mit CSOM zu erhalten?

Ein paar verwandte Fragen:

  • Sollten wir zunächst immer alle Listen zurückgeben und dann eine Linq-Abfrage ausführen, um den richtigen auszuwählen?
  • In welcher Eigenschaft sollten wir verwenden, um die Liste zu erhalten?Ich möchte den URL-Namen (/ Mylist /) anstelle von Titel oder GUID verwenden, da der Titel (zumindest theoretisch) veränderbar sein sollte und GUID zwischen Umgebungen (dev / test / qa / on-collisites / o365) schwierig wird.Gibt es eine Eigenschaft für diesen URL-Namen (ohne Web-URL)
  • würde der Ansatz die schnellste in den meisten Szenarien sein?

    Ich möchte auch etwas anderes hinter der vorgeschlagenen Lösung haben.

War es hilfreich?

Lösung

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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top