.. include:: /../common/authors.txt

Lists

The Lists API contains methods that makes it easier to work with lists and libraries in SharePoint.

You reach the Lists API through the following service

OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx);

AddFileToList

Use this method to create a file in a library based on a supplied byte array containing the file data.

void OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .AddFileToList(Guid listId, string folderServerRelativeUrl, string fileName, byte[] data);

Pass in the GUID of the library, a server relative Url to a folder (or empty string to add in root folder) and a file name.

Optionally, you can also supply a boolean indicating if the file should be published or not

void OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .AddFileToList(Guid listId, string folderServerRelativeUrl, string fileName, byte[] data, bool publish);

GetAllDocumentLibraries

To get information about all document libraries on the current web, use the following method

IEnumerable<ListIdentifier> OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .GetAllDocumentLibraries();

The returned array contains ListIdentifier objects containing for example Title, Id and ListUrl for the document libraries.

GetAllImageLibraries

To get information about all image libraries on the current web, use the following method

IEnumerable<ListIdentifier> OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .GetAllImageLibraries();

The returned array contains ListIdentifier objects containing for example Title, Id and ListUrl for the image libraries.

GetDocuments

To get documents from a library, you can use the following method

IEnumerable<DocumentIdentifier> OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .GetDocuments(Guid listId, ListQuery listQuery, bool recursive = true, string folderServerRelativeUrl = "");

Supply a ListQuery object to filter the results.

To get a paged subset of the documents, you can instead use the following method

IEnumerable<DocumentIdentifier> OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        GetDocuments(Guid listId, string searchString = null, int skipId = 0, int take = -1, string orderBy = null, bool ascending = true, bool isGetAbsoluteUrl = false);

Passing in a skipId decides from which item to start fetching, and take sets the number of documents to return. You can also supply orderBy and ascending parameters to decide the sort order.

The returned DocumentIdentifier class contains basic information about the documents in the library, for example Id, Title, FileName, DocumentUrl and more.

GetDocumentsByFolder

Much like the GetDocuments method, you can use this method to get a paged subset of documents, but in a specific folder

IEnumerable<DocumentIdentifier> OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        GetDocumentsByFolder(Guid listId, string folderUrl, string searchString = null, int skipId = 0, int take = -1, string orderBy = null, bool ascending = true);

Pass in site relative folderUrl

GetListItems

Use this method to get list items from a list

IEnumerable<ListItem> OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .GetListItems(Guid listId, ListQuery listQuery);

Note that this returns the full ListItem objects. Use the listQuery parameter to filter what items are returned.

GetPageList

Note

Publishing webs only

To get the Pages list of the current web use one of the following methods

List OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .GetPageList(Web web, string webUrl);

or (to target a specific list)

List OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        .GetPageList(Web web, string webUrl, string listId);

GetPageListId

Note

Publishing webs only

To get the Guid of the Pages library on a publishing web, use the following method

Guid OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        GetPageListId(Web web, string webUrl);

GetPageListUrl

Note

Publishing webs only

To get the URL of the Pages library on a publishing web, use the following method

string OmniaApi.WorkWith(Ctx.Omnia()).Lists(Ctx)
        GetPageListUrl(Web web, string webUrl);