473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 2314
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

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

Similar topics

7
by: Pan Am | last post by:
My Web hosting service does not support multiple directories... Can anyone suggest a Unix script that traverses a HTML tree and produces a working "single directory" version of the same? TIA ...
3
by: olle | last post by:
Hi everyone. Beging a newbee to asp.net and used to work with traditional asp I have one problem working with a datalist. 1/ I make a dataset as as session variable like session("employees") 2/...
3
by: SB | last post by:
Hi, I have a super-simple need to just walk the files in a single directory. I thought this would do it, but "permanentFilelist" ends up containing all folders in all subdirectories. Could...
0
by: ammar_fake | last post by:
Hello there. I need a DataList to render the Gridview by providing one of the DataList values as a query for the underlaying Gridview. This does not work: SelectCommand="select * from...
2
by: suresh_nsnguys | last post by:
Hi, I am working in digital signage application where user can upload image,flash and movie files .and later thay can view the uploaded files in digital LCD screen. I am facing 1...
1
parshupooja
by: parshupooja | last post by:
Hi All, I am working in ASP.NET C#. I have image folder in my application. I want to load all images in Gridview/datalist one column and second and third column with empty texboxes. I do not know...
1
by: mil111 | last post by:
Hi, can enybody help me please. I have a gridview with column that shows the images dynamically from database (see code below). What I need it to do is check to see if there is an image in each...
1
by: Sean | last post by:
Hi, I've taken over a website, which has an admin section that is currently open. I added Forms Authentication to the admin directory with the using the location section in web.config: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.