开发者

Enumerate all folders in a SharePoint list recursively

开发者 https://www.devze.com 2022-12-31 15:11 出处:网络
Is it possible to get a list of all folders in a SharePoint document library, using SPQuery? Something you could get in file system, if you opened Windows command prompt and ran

Is it possible to get a list of all folders in a SharePoint document library, using SPQuery?

Something you could get in file system, if you opened Windows command prompt and ran

 dir /b /A:D /S

The problem is, if you create a simple SPQuery and set the viewAttributes to Scope='RecursiveAll', the result set contains items, but not the folders.

Or am I completely missing something?

Upd.: The reason for this question is (was) that I have to create a solution where a "packet of files" makes sense.

When my client speaks about a "document", he actually means an entity that may consist of multiple files and a common set of metadata for these files.

For instance, the document might be named "A letter to my grandma" (attributes: grandma's address, letter title), but it consists of several files: the actual letter in MS Word document and a JPEG picture.

So, the idea was that I could create a content type derived from Folder and add some fields to this content type (address, title). All the files placed into th开发者_如何学Pythonat folder would naturally become parts of the 'document'.

Since we expect that there will be a lot of such documents, we create a folder hierarchy of regular type of folders, too.

Now, we come to the question: how do I show a view like "Recent documents" to my client? This must work recursively to enumerate all the "documents". Recursion through SPFolder objects is way too slow due to the number of requests that have to be made. We hoped for a recursive SPQuery, but this does not seem to be solvable this way.


You should be able to get all the folders by filtering on the content type.

<Eq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Eq>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号