Our monthly Virtual Happy Hour is happening this week, Fri Feb 23!

Try our conversational search powered by Generative AI!

Iterating through the contents of UFS folder



Using the GetFiles() method of the unified file system I want to create an image gallery. As part of the gallery I need to implement pagination. Has anyone done this or knows of teh most effecient way to retrieve a subset of collection returned from getFiles()?

Thanks in advance 

Nov 11, 2008 0:11

Just a quick note, and not an answer to your question:

 If you are creating an image gallery, you should take look at the existing free module at Epicode. Have a look here:

Lars Øyvind Bodahl

Nov 11, 2008 8:11

The module includes code to implement pagination and it uses a repeater to display the images. 

It uses the following code to retrieve all images in a folder:

UnifiedDirectory dir = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(filePath) as UnifiedDirectory;
unsortedFiles = dir.GetFiles(); ArrayList arrayListSorted = new ArrayList(unsortedFiles); //creating arraylist with the pic, and do a sorting with
allFiles = (UnifiedFile[])arrayListSorted.ToArray(typeof(UnifiedFile));

Lars Øyvind Bodahl

Edited, Nov 11, 2008 8:22

GetFiles() returns an array of UnifiedFile - LINQ is great when you want to retrieve a subset of that array. (if you're on the correct .NET version that is.. :-))

UnifiedFile[] files = directory.GetFiles();

// First X elements:
var tenFirst = files.Take(10);

// Skip X element before taking Y elements.
var nextTen = files.Skip(10).Take(10);


Edited, Nov 12, 2008 7:01
Nov 13, 2008 13:10


Thanks Magnus.

LINQ looks perfect, however when I use Take(10) on a collection of 14 I get a null collection back, have you had any issues with the unfiedCollection like this?



Nov 13, 2008 13:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.