Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,I am trying to implement paging functionality in my website so that only 4 blogs written by Admin may be shown on the web page.But the problem is that I have no database, so
I have to do it with the text files because Admin writes blogs on text file to upload it on the site.Please help me to do this.
Thanks in Advance.
Akhilesh Pathak
Posted
Updated 16-Feb-13 21:36pm
v2
Comments
Muthuraja Irullandi 17-Feb-13 8:53am    
Hi,
How you are storing the text files? Is the folder is common? Can you try implementing the functionality by using the text files count?
Akhilesh Kumar Pathak 17-Feb-13 10:11am    
Yes text file is in common folder.I did not try paging functionality by using text file count.
I have no idea what should I do as I am quite new for this type of task.So I expect some help
from you.

1 solution

Paging process need to implement based on files in a directory. The following method will return 3(pagesize) FileInfo objects based on pageIndex from a specific directory.
C#
private IList<FileInfo> GetFiles(string directory, int pageIndex)
{
    var fileInfoList = new List<FileInfo>();
    int pageSize = 3;//Assume that page size is 3
    string[] fileFullNames = Directory.GetFiles(directory);

    int start =  pageIndex * pageSize ;
    int loopCounter = 0;
    for (int index = start; index < fileFullNames.Count(); index++)
    {
        fileInfoList.Add(new FileInfo(fileFullNames[index]));
        loopCounter++;
        if (loopCounter == pageSize)
            break;
    }
    return fileInfoList;
}


Client code as follows
C#
IList<FileInfo> page1 = GetFiles("D:\\FileList", 0);
IList<FileInfo> page2 = GetFiles("D:\\FileList", 1);
IList<FileInfo> page3 = GetFiles("D:\\FileList", 2);
IList<FileInfo> page4 = GetFiles("D:\\FileList", 3);

Your client code may be differ based on control you use for. Like gridview/client side table etc just you adjust these code. I show here how to call that paging method 3 times with different page index; I test it with create a directory and save 10 different files there and pick files page by page.
 
Share this answer
 
v2
Comments
Akhilesh Kumar Pathak 19-Feb-13 6:23am    
Thanks Mr.S M Ahasan Habib

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900