getting a file list

J

Jerry

Hi!,

I am just starting out in c# here and what I want to do is get a list of
files, list them in a a listBox. I want the to beable to select either 1,
2, ... ALL files in this list and execute a job on them.

Here is what I have so far:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace VFSQL

{

public partial class VFFormDataToSQL : Form

{

public VFFormDataToSQL()

{

InitializeComponent();

Page_Load();

}

void Page_Load()

{

DirectoryInfo di = new DirectoryInfo(@"V:\Excalibur\TextData");

FileInfo[] rgFiles = di.GetFiles("*.FDF");

lBDataFiles.Items.AddRange = rgFiles;

// lBDataFiles_SelectedIndexChanged( rgFiles );

foreach (FileInfo fi in rgFiles)

{

Console.WriteLine(fi.Name);

}

}

private void Form1_Load(object sender, EventArgs e)

{

Page_Load();

}

private void lBDataFiles_SelectedIndexChanged(object sender, EventArgs e)

{

}

private void bExit_Click(object sender, EventArgs e)

{

this.Close();

}

}

}



Thanks,

Jerry
 
M

Morten Wennevik [C# MVP]

Hi Jerry,

Well, you seem to have managed to display the files in a ListBox. Since
you want to be able to select several files I would drop the
SelectedIndexChanged event, enable multiselect on the ListBox and put a
Button that triggers the job. When the buttons is clicked, use
lBDataFiles.SelectedItems or lBDataFiles.SelectedIndices to determine
which of the files have been selected and do the job.

You might also want to consider using a CheckedListBox for user
friendliness (makes it easier for the user to understand that several
files can be selected), and maybe a "Select All" button.


Hi!,

I am just starting out in c# here and what I want to do is get a list of
files, list them in a a listBox. I want the to beable to select either
1,
2, .. ALL files in this list and execute a job on them.

Here is what I have so far:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace VFSQL

{

public partial class VFFormDataToSQL : Form

{

public VFFormDataToSQL()

{

InitializeComponent();

Page_Load();

}

void Page_Load()

{

DirectoryInfo di = new DirectoryInfo(@"V:\Excalibur\TextData");

FileInfo[] rgFiles = di.GetFiles("*.FDF");

lBDataFiles.Items.AddRange = rgFiles;

// lBDataFiles_SelectedIndexChanged( rgFiles );

foreach (FileInfo fi in rgFiles)

{

Console.WriteLine(fi.Name);

}

}

private void Form1_Load(object sender, EventArgs e)

{

Page_Load();

}

private void lBDataFiles_SelectedIndexChanged(object sender, EventArgse)

{

}

private void bExit_Click(object sender, EventArgs e)

{

this.Close();

}

}

}



Thanks,

Jerry
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Advise , next time you post some code paste it first in notepad , this will
eliminate the empty lines.

Then, what is your problem? What is that you do not know how to do?
basically you have to allow multipleselectionin the listbox using
Listbox.SelectionMode = SelectionMode.Multiple

then add a button and on the click of the button get the selected elemtnts


| Hi!,
|
| I am just starting out in c# here and what I want to do is get a list of
| files, list them in a a listBox. I want the to beable to select either 1,
| 2, ... ALL files in this list and execute a job on them.
|
| Here is what I have so far:
|
| using System;
|
| using System.Collections.Generic;
|
| using System.ComponentModel;
|
| using System.Data;
|
| using System.Drawing;
|
| using System.Text;
|
| using System.Windows.Forms;
|
| using System.IO;
|
| namespace VFSQL
|
| {
|
| public partial class VFFormDataToSQL : Form
|
| {
|
| public VFFormDataToSQL()
|
| {
|
| InitializeComponent();
|
| Page_Load();
|
| }
|
| void Page_Load()
|
| {
|
| DirectoryInfo di = new DirectoryInfo(@"V:\Excalibur\TextData");
|
| FileInfo[] rgFiles = di.GetFiles("*.FDF");
|
| lBDataFiles.Items.AddRange = rgFiles;
|
| // lBDataFiles_SelectedIndexChanged( rgFiles );
|
| foreach (FileInfo fi in rgFiles)
|
| {
|
| Console.WriteLine(fi.Name);
|
| }
|
| }
|
| private void Form1_Load(object sender, EventArgs e)
|
| {
|
| Page_Load();
|
| }
|
| private void lBDataFiles_SelectedIndexChanged(object sender, EventArgs e)
|
| {
|
| }
|
| private void bExit_Click(object sender, EventArgs e)
|
| {
|
| this.Close();
|
| }
|
| }
|
| }
|
|
|
| Thanks,
|
| Jerry
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top