Microsoft Graph REST API v1.0 Get listItem(10.000.000 List Item from a SharePoint list)

Sezgin Tabak 86 Reputation points
2021-01-22T08:19:39.977+00:00

Dear Mr./Mrs.

I am using your solution(Ref. Link: https://learn.microsoft.com/en-us/graph/api/listitem-get?view=graph-rest-1.0&tabs=csharp) for our enterprise software(CSOM+C#). We have more than 10.000.000 item in our SharePoint List and we would like to retrieve all of them to do specific transactions(ex: compare items from SharePoint List with items from a CSV-File (on File Server)). How we can do it?

I am asking for your valuable solutions/suggestions.

Kind Regards,
Sezgin Tabak

Microsoft 365 and Office | SharePoint | For business | Windows
{count} votes

Accepted answer
  1. Baker Kong-MSFT 3,801 Reputation points
    2021-01-25T03:12:42.04+00:00

    Hi @Sezgin Tabak ,

    I see that you're trying to fetch a large list. As @Deva-MSFT suggested, you may need to use pagination, or you may receive list view threshold error.

    If you're using MS Graph Service Client (C#), please take a reference of the below tutorial:

    demo1:

    List<ListItem> Allitems = new List<ListItem>();  
      
                var items = await graphClient.Sites["abc.sharepoint.com,5ae427d1-c859-4c58-97c4-e20ad27b850b,352d1542-3d0a-4f99-a529-723e41552082"]  
                    .Lists["40418c29-06c3-442e-9d01-972d4e9f0129"]  
                    .Items  
                    .Request()  
                    .Top(100)    
                    .GetAsync();  
                  
                var i = 1;  
                var pageIterator = PageIterator<ListItem>  
                    .CreatePageIterator(graphClient, items, (e) =>  
                    {  
                        Console.WriteLine($"{i++} {e.WebUrl}");   
                        Allitems.Add(e);  
                        return true;  
                    });  
      
                await pageIterator.IterateAsync();  
    

    demo2:

    var totalitems = new List<Microsoft.Graph.ListItem>();  
      
      
                var items = graphClient  
                    .Sites["abc.sharepoint.com,5ae427d1-c859-4c58-97c4-e20ad27b850b,352d1542-3d0a-4f99-a529-723e41552082"]  
                    .Lists["40418c29-06c3-442e-9d01-972d4e9f0129"].Items  
                    .Request()  
                    .GetAsync().Result;  
      
                totalitems.AddRange(items.CurrentPage);  
                while (items.NextPageRequest != null)  
                {  
                    items = items.NextPageRequest.GetAsync().Result;  
                    totalitems.AddRange(items.CurrentPage);  
                }  
      
                Console.WriteLine(totalitems);  
    

    Pagination using CSOM:

    More references:

    Best Regards,
    Baker Kong


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sezgin Tabak 86 Reputation points
    2021-02-03T14:59:18.837+00:00

    Hi @Baker Kong-MSFT ,

    I am sorry for late answer. Thank you very much for both your valuable time and your valuable answer.

    I wish you a healthy life and great achievements with your works.

    Best,
    Sezgin

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.