Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
DirectoryInfo dir = new DirectoryInfo

how to use DirectoryInfo dir = new DirectoryInfo in my code i means to say which class i have ti include

i am using here in my code but here is the error

what i have to include

C#
private void Form2_Load(object sender, EventArgs e)
        {
                DirectoryInfo dir = new DirectoryInfo("@C:\\image1");

                foreach (FileInfo file in dir.GetFiles())
                {

                    try
                    {

                        this.imageList1.Images.Add(Image.FromFile(file.FullName));

                    }

                    catch
                    {

                        Console.WriteLine("This is not an image file");

                    }

                }

                this.listView1.View = View.LargeIcon;

                this.imageList1.ImageSize = new Size(32, 32);

                this.listView1.LargeImageList = this.imageList1;

                //or 

                //this.listView1.View = View.SmallIcon;

                //this.listView1.SmallImageList = this.imageList1;



                for (int j = 0; j < this.imageList1.Images.Count; j++)
                {

                    ListViewItem item = new ListViewItem();

                    item.ImageIndex = j;

                    this.listView1.Items.Add(item);

                }

            }
Posted
Updated 11-Jul-11 20:55pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Jul-11 2:54am    
Where is the problem? Error report please, with lines of code.
--SA
kami124 12-Jul-11 2:56am    
ya at DiractoryInfo
there is an error that type or namespace could not found.

Use System.IO.DirectoryInfo.
or check whether you have reference to System.IO
 
Share this answer
 
Comments
kami124 12-Jul-11 3:03am    
ya now the error is finished but the image is not display in listview
now what to do
Sergey Alexandrovich Kryukov 12-Jul-11 3:04am    
Same time. Yes, almost correct, but: 1) System.IO referenced as System (not System.IO which is a part of it); 2) there are two more forms of using name space; please see my solution.
Stop programming without learning how to use name spaces.

Use:

C#
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(directoryName);


or

C#
using System.IO;

//...

DirectoryInfo dir = new DirectoryInfo(directoryName);


or

C#
using DirectoryInfo = System.IO.DirectoryInfo; //alias

//...

DirectoryInfo dir = new DirectoryInfo(directoryName);


—SA
 
Share this answer
 
v2
Comments
kami124 12-Jul-11 3:09am    
ok i will but you are no body to say like this be polite during sharing information its happen sometime that you miss little things it dosent you degrade someone but still i thans for your co operation.
Sergey Alexandrovich Kryukov 12-Jul-11 4:12am    
Just the opposite: when I make a mistake, I fix it and say thank you and allow myself no exclusions.

Let's see what you do. I help you and simply give you a general advice on how to approach programming (I mean, read manual on the language; how come you see anything negative in it?), and what do you do in response? Very nice. Who is impolite? Just think about it.

Now, will you consider formally accepting this answer (green button)? -- thank you.
--SA
vivekse 12-Jul-11 3:24am    
SA,You are right. +5 from my side.
Sergey Alexandrovich Kryukov 12-Jul-11 4:06am    
Thank you, Vivekse.
--SA
Espen Harlinn 12-Jul-11 9:44am    
My 5, perhaps a bit harsh on the OP though :)

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