Click here to Skip to main content
12,358,339 members (69,792 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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 16-Feb-13 21:32pm
Edited 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
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
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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100