Wednesday, March 15, 2017

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

string FolderName = "Peak";
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList oList = web.Lists["YourListName"];
                        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;
                            }
                        }
                    }

No comments:

Post a Comment