472,789 Members | 1,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 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 2286
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.