Home > SharePoint Development > Get all the item of specific folder of Document Library or list in Sharepoint using C#

Get all the item of specific folder of Document Library or list in Sharepoint using C#

                    string FolderName = "Finance";
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList oList = web.Lists["ListName"];

                        SPListItemCollection collListItems = null;
                        foreach (SPFolder subFolder in oList.RootFolder.SubFolders)
                        {
                            if (subFolder.Name.ToLower() == FolderName.ToLower().Trim())
                            {
                                SPQuery oQuery = new SPQuery();
                                oQuery.Query = "<OrderBy><FieldRef Name=’Modified’ Ascending=’False’ /></OrderBy>";
                                oQuery.Folder = subFolder;
                                collListItems = oList.GetItems(oQuery);
                                break;
                            }
                        }
                    }

Advertisements
  1. Brian
    28/04/2012 at 2:31 am

    How does this code even compile? What are it’s dependancies?

    • 30/04/2012 at 1:00 pm

      Hi Brian,

      You only need to add Microsoft.Sharepoint namespace and it will work.
      The objective the above code is to get all items of specific folder from Sharepoint Document library.

      Cheers
      Sanjiv

  2. Brian
    30/04/2012 at 7:56 pm

    Hi Sanjiv, is this an example of a windows application codebase? or a web application? I’m trying to retrieve from sharepoint 2007 the folder contents of a folder.

    • 01/05/2012 at 2:21 pm

      Hi,
      This is an generic code that can be used for either window app or web application for Sharepoint.

  3. Riyaz
    01/02/2014 at 5:54 pm

    Thanks for sharing knowledge. 🙂

  4. 21/03/2014 at 9:55 pm

    Hey there! Do you use Twitter? I’d like to follow you
    if that would be okay. I’m undoubtedly enjoying your blog and look
    forward to new posts.

  1. 12/09/2014 at 3:21 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: