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

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

    • 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

  1. 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.

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