show image on webpage using C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramsham
    New Member
    • Feb 2010
    • 10

    show image on webpage using C#

    HI,

    I am quite new in this field.I am developing one C# web application .can you help me with following stuff.

    I want to Display images from a folder which contains nearly 1000 images.

    That image files in folder(means image itself) has names like 15_1,15_2,15_5, 15_40,18_1,18_3 ... where first field is id which i have to compare with plantid field and if match found then show all the images i.e. say plantid=15 then if plantid=imgeid is true then show the images with names 15_1,15_2,15_5, 15_40

    1.how i will get that 15 for comparison?
    2.which control is used to show images?

    Please help me !

    Thanks in advance for spending time here for me.thanks again!!!
  • mohanavel
    New Member
    • Nov 2008
    • 2

    #2
    For spliting you can take the file name and split using split("_"), then you will get array of items among that first is the value required for you.

    Comment

    • semomaniz
      Recognized Expert New Member
      • Oct 2007
      • 210

      #3
      Please show us what you have done and what error you are receiving.

      Comment

      • ramsham
        New Member
        • Feb 2010
        • 10

        #4
        Originally posted by mohanavel
        For spliting you can take the file name and split using split("_"), then you will get array of items among that first is the value required for you.
        I am using C# to Develop one web Site that requires this stuff.
        Some how i got that code with trial and error basis .
        the upcoming problem is that am unable to show many images it just shows last that was compared.

        Here is that code ,Can any one tell me how to show that images if they are more than one match found.Is their any that shows slide show ?
        Please help it's just near to Finish .Thanks for getting here for me.



        foreach (string filepath in Directory.GetFi les("D:/WEB/SampleImages"))
        {
        string imagename = new FileInfo(filepa th).Name;
        //Response.Write( "<script>alert( 'HIiiii')</script>" + imgFile);
        string imageid = imagename.Split ('_')[0].ToString();
        SqlDataReader plantid = obj_bl_dravya.s elect_iden_rb_i mageID(lstbxsea rch.SelectedIte m.Text.ToString ());
        plantid.Read();
        string id = plantid.GetValu e(0).ToString() ;
        if (imageid == id)
        {
        Image1.ImageUrl = filepath.ToStri ng();

        // Response.Write( "<script>alert( 'HIiiii')</script>" + imgFile + "\n");
        }

        Comment

        • ramsham
          New Member
          • Feb 2010
          • 10

          #5
          This is the ans that i had figure out!!!

          THANKS TO EVRYBODY FOR THEIR VALUABLE SUPPORT!!!!

          //To show Images
          int i = 1;
          pnlImages.Heigh t = 200;
          pnlImages.Width = 150;
          SqlDataReader plantid = obj_bl_dravya.s elect_iden_rb_i mageID(lstbxsea rch.SelectedIte m.Text.ToString ());
          plantid.Read();

          if (plantid.HasRow s)
          {
          string id = plantid.GetValu e(0).ToString() ;
          foreach (string filepath in Directory.GetFi les("D:/WEB/DRAVYAGUNA/images_Botinfo" ))
          {
          string img_name = new FileInfo(filepa th).Name;
          string img_id = img_name.Split( '_')[0].ToString();
          string img_path;
          //pnlImages.Contr ols.Clear();
          if (img_id == id)
          {
          Label lblspace = new Label();//to give space between images
          ImageButton imgbtn = new ImageButton();
          imgbtn.Height = 100;
          imgbtn.Width = 80;
          imgbtn.ID = "imgbtn" + i;
          img_path = "~/DRAVYAGUNA/images_Botinfo/" + img_name.ToStri ng();
          imgbtn.ImageUrl = img_path;
          imgbtn.PostBack Url = "~/DRAVYAGUNA/ViewImage.aspx? img_id=" + img_name;

          lblspace.ID = "lblblank" + i;
          lblspace.Text = "&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp; ";
          //lblspace.Height = 25;
          //lblspace.Width = 15;
          pnlImages.Contr ols.Add(imgbtn) ;
          pnlImages.Contr ols.Add(lblspac e);
          pnlImages.Visib le = true;
          if (i % 2 == 0)
          {
          lblspace.Text = "</br></br>";
          }
          i++;

          Comment

          Working...