Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm looking for a little help.

I'm trying to write a programme that allows me to display pictures from my 'Pictures' folder on a listbox in C# and when a picture is selected I want it to appear on the listbox? I can get a single picture but not a whole folders worth. I'm trying to implement this on a Windows Form.

Can anyone help?
Posted
Updated 9-Oct-13 23:35pm
v2
Comments
Shubh Agrahari 10-Oct-13 5:20am    
its nothing just playing with that specific paths.......

hello

may this will help you...

read it carefully try to implement


In Web Application
http://stackoverflow.com/questions/2629723/how-do-you-display-a-list-of-images-from-a-folder-on-hard-drive-on-asp-net-web[^]

try this for Window Application
http://stackoverflow.com/questions/10516167/populate-files-into-a-listbox-from-a-folder-in-c-sharp-windows-forms[^]
if any error or problem occur let me know......

Happy To Help!!!
 
Share this answer
 
v2
Comments
Member 10327451 10-Oct-13 5:37am    
Hi sorry, I forgot to add that trying to do it on a Windows Form first, before migrating to a wep application.
Shubh Agrahari 10-Oct-13 6:23am    
okk then try second link .
Member 10327451 12-Oct-13 6:16am    
Hi,

This is my code and I'm getting the error 'The name 'folderBrowserDialog1' does not exist in the current context' but I can't see why not and it's not pulling pictures from my picture folder.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Windows.Forms.FolderBrowserDialog;

namespace Pictures
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnOpen_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{

getPics(folderBrowserDialog1.SelectedPath);// getl list of files
}
}
public void getPics(string fPath)
{

foreach (string file in Directory.GetFiles(fPath))
{
if (checkIfimage(file))//check if file is image
{
listBox1.Items.Add(file);
}
}
}


public bool checkIfimage(string fname)
{
bool isImage = false;
string extension = Path.GetExtension(fname).ToLower();

if (extension == ".jpg" | extension == ".png" | extension == ".bmp")
{
isImage = true;
}
return isImage;
}
}
}

Can you help? Thanks
Shubh Agrahari 15-Oct-13 8:43am    
You really need to search About folderBrowserDialog..what it do and all that...need little Practice...You need to 1st make object of folderBrowserDialog and then Call it with Open Property that Basically open the Dialog box for choosing Pictures....do Google About it
please go through these articles

Custom List Box with Cool Effects[^]

ListBox with Icons[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900