Iterating through the contents of UFS folder

Vote:
 

Hi,

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 

#25873
Nov 11, 2008 0:11
Vote:
 

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:
https://www.coderesort.com/p/epicode/wiki/PictureGallery

--
Lars Øyvind Bodahl
www.epinova.no 

#25877
Nov 11, 2008 8:11
Vote:
 

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
www.epinova.no 

#25878
Edited, Nov 11, 2008 8:22
Vote:
 

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);

/magnus

#25914
Edited, Nov 12, 2008 7:01
Vote:
 
#25944
Nov 13, 2008 13:10
Vote:
 

Hi,

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?

Regards,

Ian

#25945
Nov 13, 2008 13:11