Reading Images in Datalist/gridview from single directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parshupooja
    New Member
    • Jun 2007
    • 159

    Reading Images in Datalist/gridview from single directory

    Hello,

    I am using ASP.Net C#. I am trying to create a datalist on asp.net page. I want 3 columns: Image, Title and Description.
    My problem is I have tons of images in single directory based on quater system. I want this datalist in such a way that it should automatically load all the images in first column one by one based on current quater and second and third column empty, so that user can add title and description to image.

    after adding description and title to all images I will save this information into new table.

    Any Idea? any help will be appreciated.

    Thanks
  • kunal pawar
    Contributor
    • Oct 2007
    • 297

    #2
    'try this code list out all image from Directory, U can add these File names in Datatable and thn Add tht DataTable as DataSource to DataGrid or Data List

    ' Check whether Path is Exist or not
    If Not Directory.Exist s(sPath) Then Exit Sub

    Try

    Dim di As New DirectoryInfo(s Path)
    Dim aryFi As System.IO.FileI nfo() = di.GetFiles("*. jpg")
    Dim fi As System.IO.FileI nfo
    For Each fi In aryFi
    sFilename = fi.Name
    Next
    Catch ex As Exception
    End Try

    Comment

    • parshupooja
      New Member
      • Jun 2007
      • 159

      #3
      Hey Kunal,

      Can u plz provide smthing Asp.net C# and elaborate more.

      Thanks

      Originally posted by kunal pawar
      'try this code list out all image from Directory, U can add these File names in Datatable and thn Add tht DataTable as DataSource to DataGrid or Data List

      ' Check whether Path is Exist or not
      If Not Directory.Exist s(sPath) Then Exit Sub

      Try

      Dim di As New DirectoryInfo(s Path)
      Dim aryFi As System.IO.FileI nfo() = di.GetFiles("*. jpg")
      Dim fi As System.IO.FileI nfo
      For Each fi In aryFi
      sFilename = fi.Name
      Next
      Catch ex As Exception
      End Try

      Comment

      • nateraaaa
        Recognized Expert Contributor
        • May 2007
        • 664

        #4
        Originally posted by parshupooja
        Hey Kunal,

        Can u plz provide smthing Asp.net C# and elaborate more.

        Thanks
        Try this code converter tool.

        Nathan

        Comment

        • parshupooja
          New Member
          • Jun 2007
          • 159

          #5
          Hello,

          This is what i tried, I gave me result in Label

          Blue hills.jpg
          Sunset.jpg
          Water lilies.jpg
          Winter.jpg

          But what shd i do next . I need to show all these images in first column of gridview one by and than second and third column with empty textboxes.

          [code=C#]

          using System.IO;

          public partial class Images: System.Web.UI.P age
          {
          string strDriveLetter = "C:/";
          string strDefaultPath = "Documents and Settings/All Users/Documents/My Pictures/Sample Pictures";
          protected void Page_Load(objec t sender, EventArgs e)
          {
          string strPath;
          // check if the query string variable "strPath" has a value
          // if it does, we are navigating a folder that is under the root folder
          // if it does not, we start at the root folder by default
          if (Request.QueryS tring["strPath"] != null)
          {
          strPath = Request.QuerySt ring["strPath"];
          }
          else
          {
          strPath = strDefaultPath;
          }

          DisplayDirConte nts(strPath);

          }

          private void DisplayDirConte nts(string strPath)
          {


          // function to display list of folders and files in specified path
          // define some arrays
          DirectoryInfo[] aryDirectories;
          FileInfo[] aryFiles;

          // variable to store the complete file system path to the folder
          string strFSPath = strDriveLetter + strPath;

          // some string manipulation to get the name of the current script
          string strCurrentScrip t = Request.ServerV ariables["URL"];
          string[] arrURL = strCurrentScrip t.Split('/');
          strCurrentScrip t = arrURL[arrURL.Length - 1];
          // instantiate local instance of DirectoryInfo object
          DirectoryInfo objCurrentDirec tory = new DirectoryInfo(s trFSPath);

          // get the directories present in the current folder
          // as an array of DirectoryInfo objects
          aryDirectories = objCurrentDirec tory.GetDirecto ries();

          // check if the current folder has any files
          if (aryFiles.Lengt h != 0)
          {

          // if it does, then iterate and
          // display the information about each file
          foreach (FileInfo objFile in aryFiles)
          {
          output.Text += objFile.Name;
          output.Text += "<br />";

          }
          }

          }


          }


          [/code]

          [code=html]
          <asp:label id="output" runat="server" style="font: 14px, Arial"/>

          [/code]

          Originally posted by nateraaaa
          Try this code converter tool.

          Nathan

          Comment

          Working...