Get all documents from a Document Set Programmatically

Here is a quick post on how to get all documents from a document set programmatically:

//First getting reference to the list:

SPList myList= web.Lists.TryGetList(“ListName”);


string strquery = “<Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>”  +           “DocumentSetName” + “</Value></Eq></Where>”;
SPQuery strcamlquery = new SPQuery();
strcamlquery.Query = strquery;
//getting reference to the document set item inside the list
SPListItem docsetitem = myList.GetItems(camlquery)[0];

//Now to loop through items in the document set

SPQuery itemDocSetQuery = new SPQuery();
itemDocSetQuery.Folder = docsetitem.Folder;
SPListItemCollection items = myList.GetItems(itemDocSetQuery);


That was a quick post, but I am sure this will be helpful to someone out there.

One thought on “Get all documents from a Document Set Programmatically

  1. What’s Going down i am new to this, I stumbled upon this I’ve discovered It
    positively useful and it has helped me out loads. I am hoping to contribute & aid different users like its aided me.
    Great job.

Leave a Reply

Your email address will not be published. Required fields are marked *