Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6751915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:59:02+00:00 2026-05-26T12:59:02+00:00

I have a list containing folders and items. The folders are a specific content

  • 0

I have a list containing folders and items. The folders are a specific content type based on folder, but with properties.

A folder can contain subfolders and subitems. A subfolder can contain sub-subfolders and so on. I already managed to get all items and folders using this way:

    void TraverseList(SPList list)
    {
        Trace.WriteLine("Traversing list: " + list.Title);
        Trace.WriteLine("Base type: " + list.BaseType.ToString());
        TraverseListFolder(list.RootFolder);
    }

    void TraverseListFolder(SPFolder folder)
    {
        SPQuery qry = new SPQuery();
        qry.Folder = folder;
        Trace.WriteLine("Foldername: " + folder.Name);
        SPWeb web = null;

        try
        {
            web = folder.ParentWeb;
            SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);

            foreach (SPListItem subitem in ic)
            {
                SPFieldLookupValue temp = new SPFieldLookupValue(subitem["TargetPage"].ToString());
                Trace.WriteLine("TargetPage: " + temp);
                Trace.WriteLine("ItemName: " + subitem.Name);
                if (subitem.Folder != null)
                {
                    TraverseListFolder(subitem.Folder);
                }
            }
        }
        catch (Exception ex)
        {
            Trace.WriteLine(ex.Message);
            throw;
        }
        finally
        {
            if (web != null)
            {
                web.Dispose();
            }
        }
    }

The problem in this solution is that I have to send a new query for every folder, which is getting imperformant when the list is growing. Is there a way to get the whole list with one call, without loosing the folder/item structure?

Thank you for reading this!

Edit: It’s not a requirement to use CAML. But there is a restriction I forgot: I’m not able to use webservices, due to customer restrictions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:59:02+00:00Added an answer on May 26, 2026 at 12:59 pm

    Fetch the root and use

    qry.ViewAttributes = "Scope='RecursiveAll'";
    

    See also: Query to get all items in a list including items in the sub folders in SharePoint

    And: http://www.ktskumar.com/blog/2009/07/retrieve-all-folders-from-list/

    HTH
    Alex

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table containing a list of folders, each folder has an ID
I have a list containing 98 items. But each item contains 0, 1, 2,
I have an array list containing 5 bulbs. I can iterate throuh them like
I have a list containing objects of type numpy.ndarray, all list elements has same
Can I have a List containing one string and two numbers? Or I can
I have a List containing a bunch of strings that can occur more than
I have a List containing several keywords. I foreach through them building my linq
I have a list containing a tuples and long integers the list looks like
I have a list containing version strings, such as things: versions_list = [1.1.2, 1.0.0,
I have a dropdown list containing the days of the week - Monday to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.