adding files to listview in C#

I have a Listview and an "ADD" button,when I click on ADD i should be able to browse the files in computer, select files and when click OK or the Open, the file list should be added in the listview...how to do that...is listview correct or any other alternative...?

Answers


ListView should be fine for file listing. Just be aware that longer file paths are difficult to see (have to horizontally scroll which is bad!) if you are gonna just add the full path to list. You can toy with the idea of other representation like:

File.Txt (C:\Users\Me\Documents)
C:\Users\..\File.Txt
etc

As far as doing it using code is concerned, you will need to use OpenFileDialog control to let user choose the files.

var ofd = new OpenFileDialog ();
//add extension filter etc
ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
if(ofd.ShowDialog() == DialogResult.OK)
{
    foreach (var f in openFileDialog1.FileNames)
    {
        //Transform the list to a better presentation if needed
        //Below code just adds the full path to list
        listView1.Items.Add (f);

        //Or use below code to just add file names
        //listView1.Items.Add (Path.GetFileName (f));
    }
}

Need Your Help

Force browser to use new CSS

c# asp.net css master-pages

Is there a way to check if the user has a different version of the CSS cached by their browser and if so force their browser to pull the new version?

Encoding/decoding NSImage

ios objective-c osx file-io encoding

I'm working on an OSX app and need to save a custom class's information, so I am trying to index it using NSCoder; however, one of the objects I'm trying to encode/decode in the class is an NSImage...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.