473,408 Members | 1,845 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,408 software developers and data experts.

fetching image from folder and display in listview

parshupooja
159 100+
Contact Reply




1 point Member
propoo
Joined on 08-31-2007, 10:32 PM
Posts 3
Hey all ,

I am using following code to check if there is any image into my folder and if there are images it should load name into the listview. To do that I am first checking if there are any image and I am saving that name into datatable and finally assigining datatable as a source to listview.

My problem is it shows all the names of imags as first or single record in listview whereas if i try to display in label is shows a break

Result for label

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


Result for listview

Blue hills.jpg<br/>Sunset.jpg<br/>Water lilies.jpg<br/>Winter.jpg<br/>
Expand|Select|Wrap|Line Numbers
  1. using System.IO;
  2.  
  3. public partial class Image : System.Web.UI.Page
  4. {
  5.     string name="";
  6.     string strDriveLetter = "C:/";
  7.     string strDefaultPath = "Documents and Settings/All Users/Documents/My Pictures/Sample Pictures";
  8.  
  9.     protected void Page_Load(object sender, EventArgs e)
  10.     {
  11.         if (!Page.IsPostBack)
  12.         {
  13.             DataTable myDt = new DataTable();
  14.             myDt = CreateDataTable();
  15.             Session["myDatatable"] = myDt;
  16.  
  17.  
  18.             this.ListBox1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
  19.             this.ListBox1.DataBind();
  20.         } 
  21.  
  22.         string strPath;
  23.         // check if the query string variable "strPath" has a value
  24.         // if it does, we are navigating a folder that is under the root folder
  25.         // if it does not, we start at the root folder by default
  26.         if (Request.QueryString["strPath"] != null)
  27.         {
  28.             strPath = Request.QueryString["strPath"];
  29.         }
  30.         else
  31.         {
  32.             strPath = strDefaultPath;
  33.         }
  34.  
  35.         DisplayDirContents(strPath);
  36.  
  37.         AddDataToTable(this.name.ToString(), (DataTable)Session["myDatatable"]);
  38.  
  39.         this.ListBox1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
  40.         this.ListBox1.DataBind();
  41.     }
  42.  
  43.     private void DisplayDirContents(string strPath)
  44.     {   // function to display list of folders and files in specified path 
  45.         // define some arrays 
  46.         DirectoryInfo[] aryDirectories;
  47.         FileInfo[] aryFiles;
  48.  
  49.         // variable to store the complete file system path to the folder
  50.         string strFSPath = strDriveLetter + strPath;
  51.  
  52.         // some string manipulation to get the name of the current script
  53.         string strCurrentScript = Request.ServerVariables["URL"];
  54.         string[] arrURL = strCurrentScript.Split('/');
  55.         strCurrentScript = arrURL[arrURL.Length - 1];
  56.  
  57.         // instantiate local instance of DirectoryInfo object
  58.         DirectoryInfo objCurrentDirectory = new DirectoryInfo(strFSPath);
  59.  
  60.         // get the directories present in the current folder
  61.         // as an array of DirectoryInfo objects
  62.         aryDirectories = objCurrentDirectory.GetDirectories();
  63.         // get the files present in the current folder
  64.         // as an array of FileInfo objects
  65.         aryFiles = objCurrentDirectory.GetFiles("*.jpg");
  66.  
  67.         // check if the current folder has any files
  68.         if (aryFiles.Length != 0)
  69.         {
  70.             // if it does, then iterate and 
  71.             // display the information about each file
  72.             foreach (FileInfo objFile in aryFiles)
  73.             {
  74.  
  75.  
  76.                 name += objFile.ToString();
  77.                 name += "&lt;br/>";
  78.                 Label1.Text += objFile.ToString();
  79.                 Label1.Text += "&lt;br/>";
  80.  
  81.             }
  82.  
  83.         } 
  84.     }
  85.  
  86.     private DataTable CreateDataTable()
  87.     {
  88.         DataTable myDataTable = new DataTable();
  89.         DataColumn myDataColumn;
  90.         myDataColumn = new DataColumn();
  91.         myDataColumn.DataType = Type.GetType("System.String");
  92.         myDataColumn.ColumnName = "name";
  93.         myDataTable.Columns.Add(myDataColumn);
  94.         return myDataTable;
  95.     }
  96.  
  97.     private void AddDataToTable(string name, DataTable myTable)
  98.     {
  99.         DataRow row;
  100.         row = myTable.NewRow();
  101.         row["name"] = name.ToString();
  102.         myTable.Rows.Add(row);
  103.     }
  104.  
  105.  
  106.  
  107. }
  108.  
Plz help
Nov 14 '07 #1
0 2283

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

Similar topics

3
by: Ken | last post by:
I have a database called autographs.mdb that is in the "XYZ" folder in the "database" folder. I have a form in the database that I want to display a photo of the celeb on. The photos are in a...
1
by: davidgordon | last post by:
Hi, I have a form in which I need to display an image of our product. On our server is a folder which contains all the images. In our MySQL db to which our MS Access 2003 front end is linked,...
1
by: Manish Songar via .NET 247 | last post by:
I am using asp.net. I am not storing image in sql server.I store all the image in one folder. I want to access image from that folder to my client machine. Images folder (\Orchid_Image) store in...
0
by: Silvia | last post by:
Hi, I have a program that capture images and put this into a listview (using imagelist), the problem is when I delete de image the listview, when do that and capture another image, the image...
1
by: trialproduct2004 | last post by:
Hi all I am having one application where i want to implement new feature that is 'create new folder'. and display new folder name in listview. My listview is editable. My problem is i want to...
1
by: KitKat | last post by:
With the help of kind, brilliant folks, I have been working on this program that uses a combo box selection to display six different jpgs. The jps are a time stamp, and the files are located in six...
1
by: TheJediMessiah | last post by:
Hi, I have a single column listview in which I want the first row to display an image and the following rows display some text. The image is displayed correctly, being aligned to the left of the...
3
by: Thomas Satzinger | last post by:
Hallo., i just encounterd a strange thing which i cannot resolve. I am saving a bitmap created in memory to the asp temp folder (asp.net 2.0) this works fine, and i don´t want to create an...
3
by: grzegorz.gazda | last post by:
Hi all Is there any limit of images which can be added to a image list. I have a problem with this control. I added an image list in design mode and I am adding images using code. Then I want to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.