Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Display images from server folder

Display images from server folder

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpquestion
6 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SAM_India
    wrote on last edited by
    #1

    Hi ALL, I have folder in Server which contains some images. On page load I need to get the images and display them. Can any one help mw how can I solve this Thanks, Siddiqali

    J P V 3 Replies Last reply
    0
    • S SAM_India

      Hi ALL, I have folder in Server which contains some images. On page load I need to get the images and display them. Can any one help mw how can I solve this Thanks, Siddiqali

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      You have to make a path to your folder, and use DirectoryInfo and FileInfo to Get the contents of the folder into the fileinfo object. Then loop through fileinfo, and run a filter on the extension to pick out the images, plus filter out the other junk in the folder, like thumbs.db.

      Dim fb_LibraryPath As String = Nothing
      fb_LibraryPath = Context.Server.MapPath("\Product\images\Library\thumbs\")

      Dim diFiles As DirectoryInfo = New DirectoryInfo(fb_LibraryPath)
      Dim fileInfo() As FileInfo = diFiles.GetFiles("*.*", SearchOption.TopDirectoryOnly)

      If fileInfo.Length() > 0 Then
      For idx As Integer = 0 To fileInfo.Length() - 1
      Dim fileName As String = fileInfo(idx).Name
      If Not fileName.ToLower = "thumbs.db" Then
      'Create a image element by code and set the src
      End if

      next

      1 Reply Last reply
      0
      • S SAM_India

        Hi ALL, I have folder in Server which contains some images. On page load I need to get the images and display them. Can any one help mw how can I solve this Thanks, Siddiqali

        P Offline
        P Offline
        Pratik Bhuva
        wrote on last edited by
        #3

        Code To upload Your Image to folder

        YourFunctionToUploadImage()
        {
        //Check FileUpload controll has File Or not
        if (ImageFileUploadControll.HasFile)
        {
        string fileExtention = System.IO.Path.GetExtension(ImageFileUploadControll.FileName);
        //Check For Valid Extension
        if (fileExtention.ToLower() != ".jpg" && fileExtention.ToLower() != ".jpeg" && fileExtention.ToLower() != ".png")
        {
        lblUploadstatus.Text = "Invalid File Choose .jpg/.jpeg/.png/.gif";
        }
        else
        {
        //check if file already Exists in Folder
        if (File.Exists(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName)))
        {
        lblUploadstatus.Text = "File Already Exists. Rename filename";
        }
        else
        {
        //To Save Image To your Specific Location.
        //srever.mappath takes us to Folder which containing our application
        ImageFileUploadControll.SaveAs(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName));
        lblUploadstatus.Text = "Upload Status : File Uploaded Successfully";
        }
        }

        }
        else
        {
        lblUploadstatus.Text = "Please Select File";
        }
        }

        Code To Retrive Images form Folder

        PageLoadEvent()
        {
        //use DirectoryInfo to get all imageFile's Information
        DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Folder_Name/"));
        FileInfo[] fi = dir.GetFiles();

           //Now you just need to create new image control each time and add ImageUrl to it
           foreach(FileInfo f in fi)
           {
                string imageUrl = f.ToString();
                Image img = new Image();
                img.ImageUrl = "~/Folder\_Name/"+"imageUrl";
           }
        

        }

        Hope This Help

        Pratik M. Bhuva

        S 1 Reply Last reply
        0
        • S SAM_India

          Hi ALL, I have folder in Server which contains some images. On page load I need to get the images and display them. Can any one help mw how can I solve this Thanks, Siddiqali

          V Offline
          V Offline
          Vishnu Prajapati
          wrote on last edited by
          #4

          Code To Upload Image //check whether FileUpload control has file or not

          if (FileUpload1.HasFile)
          {
          string fileExtension = Path.GetExtension(FileUpload1.FileName);

            // Checkout proper file
          
          if (fileExtension.ToLower() != ".jpg" && fileExtension.ToLower() != ".jpeg")
          {
               lblMessage.Text = "Only File With .jpg and .jpeg Extension are allowed";
               lblMessage.ForeColor = System.Drawing.Color.Red;
          
          }
          else
          {
                //checkout whether file already exist or not
          
                if (File.Exists(Server.MapPath("~/Uploaded\_Image/" + FileUpload1.FileName)))
                {
                      lblMessage.Text = "Image Already Exist...Please Select Another Image";
                      lblMessage.ForeColor = System.Drawing.Color.Blue;
          
                      return;
                }
                else
                {
                    // Upload image
                 
                    FileUpload1.SaveAs(Server.MapPath("~/Uploaded\_Image/" + FileUpload1.FileName));
                    lblMessage.Text = "File Uploaded Successfully";
                    lblMessage.ForeColor = System.Drawing.Color.Green;
          
                 }
          
            }
          
          }
          

          else
          {
          lblMessage.Text = "Please Select File to be uploaded";
          lblMessage.ForeColor = System.Drawing.Color.Red;
          }

          1 Reply Last reply
          0
          • P Pratik Bhuva

            Code To upload Your Image to folder

            YourFunctionToUploadImage()
            {
            //Check FileUpload controll has File Or not
            if (ImageFileUploadControll.HasFile)
            {
            string fileExtention = System.IO.Path.GetExtension(ImageFileUploadControll.FileName);
            //Check For Valid Extension
            if (fileExtention.ToLower() != ".jpg" && fileExtention.ToLower() != ".jpeg" && fileExtention.ToLower() != ".png")
            {
            lblUploadstatus.Text = "Invalid File Choose .jpg/.jpeg/.png/.gif";
            }
            else
            {
            //check if file already Exists in Folder
            if (File.Exists(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName)))
            {
            lblUploadstatus.Text = "File Already Exists. Rename filename";
            }
            else
            {
            //To Save Image To your Specific Location.
            //srever.mappath takes us to Folder which containing our application
            ImageFileUploadControll.SaveAs(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName));
            lblUploadstatus.Text = "Upload Status : File Uploaded Successfully";
            }
            }

            }
            else
            {
            lblUploadstatus.Text = "Please Select File";
            }
            }

            Code To Retrive Images form Folder

            PageLoadEvent()
            {
            //use DirectoryInfo to get all imageFile's Information
            DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Folder_Name/"));
            FileInfo[] fi = dir.GetFiles();

               //Now you just need to create new image control each time and add ImageUrl to it
               foreach(FileInfo f in fi)
               {
                    string imageUrl = f.ToString();
                    Image img = new Image();
                    img.ImageUrl = "~/Folder\_Name/"+"imageUrl";
               }
            

            }

            Hope This Help

            Pratik M. Bhuva

            S Offline
            S Offline
            SAM_India
            wrote on last edited by
            #5

            Hi Bhuva, Thank you very much for your imp info. I am able to upload and get images, but while showing the images it takes long time. I have almost 150 images in the folder which I need to show with in no time. Request you to pls help me in solving this issue Thanks, Siddiqali

            P 1 Reply Last reply
            0
            • S SAM_India

              Hi Bhuva, Thank you very much for your imp info. I am able to upload and get images, but while showing the images it takes long time. I have almost 150 images in the folder which I need to show with in no time. Request you to pls help me in solving this issue Thanks, Siddiqali

              P Offline
              P Offline
              Pratik Bhuva
              wrote on last edited by
              #6

              You can use ajax update pannel for fast image loading.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups