Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Friends,
I am currently working in a healthcard project. In that project each files contains ID number.

First we will scan those images and stored in a folder.

I need to retrieve those images one by one dynamically from that folder.

if i click submit button it need to retrieve the next image file from that folder.

please help me on this........
Posted
Comments
[no name] 10-Aug-12 7:24am    
Help with what? You have not described any kind of a problem. Where is the code the demonstrates you problem?

Put your images in a folder named "Image" in project..

C#
    private static DirectoryInfo dir;
    private static FileInfo[] images;
    private static int currIndex=0;
    private static int count=0;
protected void Page_Load(object sender, EventArgs e)
    {
        dir = new DirectoryInfo(Server.MapPath("Image"));
        images = dir.GetFiles();
        count = images.Length;
        if (!IsPostBack)
        {
          if (count > 0)
            {
                string strImageurl = images[currIndex].Name;
                strImageurl = "~/Image/" + strImageurl;
                Image1.ImageUrl = strImageurl;
            } 
        }
   }
protected void submitbtn_Click(object sender, ImageClickEventArgs e)
    {
        if (count > 0)
        {            
            if (currIndex ==(count-1))
              {
                currIndex = 0;
              }
            else
              {
                currIndex++;
              }
            string newUrl = images[currIndex].Name;
            newUrl = "~/Image/" + newUrl;
            Image1.ImageUrl = newUrl;

        }
    }      


XML
<asp:Button ID="submitbtn" runat="server" onclick="submitbtn_Click" Text="Submit" />

<asp:image ID="Image1" runat="server" Height="375px" Width="500px"></asp:image>


at page load this will load fist image in image folder to image control and on sumbit button click load next image and this will go on in cyclic way....
 
Share this answer
 
Thank you very much friend. Its working good when i place the folder in my project.

But the folder is in D: drive i tried this following code but its showing error.

C#
private static DirectoryInfo dir;
       private static FileInfo[] images;
       private static int currIndex = 0;
       private static int count = 0;
       protected void Page_Load(object sender, EventArgs e)
       {
           dir = new DirectoryInfo(Server.MapPath(@"D:\Image"));
           images = dir.GetFiles();
           count = images.Length;
           if (!IsPostBack)
           {
               if (count > 0)
               {
                   string strImageurl = images[currIndex].Name;
                   strImageurl = "~/Image/" + strImageurl;
                   Image1.ImageUrl = strImageurl;
               }
           }
       }

       protected void submitbtn_Click(object sender, EventArgs e)
       {
           if (count > 0)
           {
               if (currIndex == (count - 1))
               {
                   currIndex = 0;
               }
               else
               {
                   currIndex++;
               }
               string newUrl = images[currIndex].Name;
               newUrl = "~/Image/" + newUrl;
               Image1.ImageUrl = newUrl;

           }
       }



ERROR:
'D:\Image' is not a valid virtual path.
 
Share this answer
 

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