469,903 Members | 1,944 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Reading Images in Datalist/gridview from single directory

parshupooja
159 100+
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
Nov 6 '07 #1
4 2160
kunal pawar
297 100+
'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.Exists(sPath) Then Exit Sub

Try

Dim di As New DirectoryInfo(sPath)
Dim aryFi As System.IO.FileInfo() = di.GetFiles("*.jpg")
Dim fi As System.IO.FileInfo
For Each fi In aryFi
sFilename = fi.Name
Next
Catch ex As Exception
End Try
Nov 7 '07 #2
parshupooja
159 100+
Hey Kunal,

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

Thanks

'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.Exists(sPath) Then Exit Sub

Try

Dim di As New DirectoryInfo(sPath)
Dim aryFi As System.IO.FileInfo() = di.GetFiles("*.jpg")
Dim fi As System.IO.FileInfo
For Each fi In aryFi
sFilename = fi.Name
Next
Catch ex As Exception
End Try
Nov 7 '07 #3
nateraaaa
663 Expert 512MB
Hey Kunal,

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

Thanks
Try this code converter tool.

Nathan
Nov 7 '07 #4
parshupooja
159 100+
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. using System.IO;
  3.  
  4. public partial class Images: System.Web.UI.Page
  5. {
  6.     string strDriveLetter = "C:/";
  7.     string strDefaultPath = "Documents and Settings/All Users/Documents/My Pictures/Sample Pictures";
  8.     protected void Page_Load(object sender, EventArgs e)
  9.     {
  10.         string strPath;
  11.         // check if the query string variable "strPath" has a value
  12.         // if it does, we are navigating a folder that is under the root folder
  13.         // if it does not, we start at the root folder by default
  14.         if (Request.QueryString["strPath"] != null)
  15.         {
  16.             strPath = Request.QueryString["strPath"];
  17.         }
  18.         else
  19.         {
  20.             strPath = strDefaultPath;
  21.         }
  22.  
  23.         DisplayDirContents(strPath);
  24.  
  25.     }
  26.  
  27.         private void DisplayDirContents(string strPath)
  28.     {
  29.  
  30.  
  31.         // function to display list of folders and files in specified path 
  32.         // define some arrays 
  33.         DirectoryInfo[] aryDirectories;
  34.         FileInfo[] aryFiles;
  35.  
  36.         // variable to store the complete file system path to the folder
  37.         string strFSPath = strDriveLetter + strPath;
  38.  
  39.         // some string manipulation to get the name of the current script
  40.         string strCurrentScript = Request.ServerVariables["URL"];
  41.         string[] arrURL = strCurrentScript.Split('/');
  42.         strCurrentScript = arrURL[arrURL.Length - 1];
  43.         // instantiate local instance of DirectoryInfo object
  44.         DirectoryInfo objCurrentDirectory = new DirectoryInfo(strFSPath);
  45.  
  46.         // get the directories present in the current folder
  47.         // as an array of DirectoryInfo objects
  48.         aryDirectories = objCurrentDirectory.GetDirectories();
  49.  
  50.             // check if the current folder has any files
  51.         if (aryFiles.Length != 0)
  52.         {
  53.  
  54.             // if it does, then iterate and 
  55.             // display the information about each file
  56.             foreach (FileInfo objFile in aryFiles)
  57.             {
  58.                 output.Text += objFile.Name;
  59.                 output.Text += "<br />";
  60.  
  61.             }
  62.         }    
  63.  
  64.    }
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
Expand|Select|Wrap|Line Numbers
  1.     <asp:label id="output" runat="server" style="font: 14px, Arial"/>
  2.  
  3.  
Try this code converter tool.

Nathan
Nov 7 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by SB | last post: by
reply views Thread by ammar_fake | last post: by
1 post views Thread by mil111 | last post: by
1 post views Thread by Sean | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.