473,698 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting a file list

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.Collecti ons.Generic;

using System.Componen tModel;

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 ()

{

InitializeCompo nent();

Page_Load();

}

void Page_Load()

{

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

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

lBDataFiles.Ite ms.AddRange = rgFiles;

// lBDataFiles_Sel ectedIndexChang ed( rgFiles );

foreach (FileInfo fi in rgFiles)

{

Console.WriteLi ne(fi.Name);

}

}

private void Form1_Load(obje ct sender, EventArgs e)

{

Page_Load();

}

private void lBDataFiles_Sel ectedIndexChang ed(object sender, EventArgs e)

{

}

private void bExit_Click(obj ect sender, EventArgs e)

{

this.Close();

}

}

}

Thanks,

Jerry
Jan 22 '07 #1
2 1926
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
SelectedIndexCh anged event, enable multiselect on the ListBox and put a
Button that triggers the job. When the buttons is clicked, use
lBDataFiles.Sel ectedItems or lBDataFiles.Sel ectedIndices 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.
On Mon, 22 Jan 2007 19:25:12 +0100, Jerry <jp******@gener al-steel.com
wrote:
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.Collecti ons.Generic;

using System.Componen tModel;

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 ()

{

InitializeCompo nent();

Page_Load();

}

void Page_Load()

{

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

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

lBDataFiles.Ite ms.AddRange = rgFiles;

// lBDataFiles_Sel ectedIndexChang ed( rgFiles );

foreach (FileInfo fi in rgFiles)

{

Console.WriteLi ne(fi.Name);

}

}

private void Form1_Load(obje ct sender, EventArgs e)

{

Page_Load();

}

private void lBDataFiles_Sel ectedIndexChang ed(object sender, EventArgse)

{

}

private void bExit_Click(obj ect sender, EventArgs e)

{

this.Close();

}

}

}

Thanks,

Jerry



--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 23 '07 #2
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 multipleselecti onin the listbox using
Listbox.Selecti onMode = SelectionMode.M ultiple

then add a button and on the click of the button get the selected elemtnts
"Jerry" <jp******@gener al-steel.comwrote in message
news:12******** *****@corp.supe rnews.com...
| 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.Collecti ons.Generic;
|
| using System.Componen tModel;
|
| 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 ()
|
| {
|
| InitializeCompo nent();
|
| Page_Load();
|
| }
|
| void Page_Load()
|
| {
|
| DirectoryInfo di = new DirectoryInfo(@ "V:\Excalibur\T extData");
|
| FileInfo[] rgFiles = di.GetFiles("*. FDF");
|
| lBDataFiles.Ite ms.AddRange = rgFiles;
|
| // lBDataFiles_Sel ectedIndexChang ed( rgFiles );
|
| foreach (FileInfo fi in rgFiles)
|
| {
|
| Console.WriteLi ne(fi.Name);
|
| }
|
| }
|
| private void Form1_Load(obje ct sender, EventArgs e)
|
| {
|
| Page_Load();
|
| }
|
| private void lBDataFiles_Sel ectedIndexChang ed(object sender, EventArgs e)
|
| {
|
| }
|
| private void bExit_Click(obj ect sender, EventArgs e)
|
| {
|
| this.Close();
|
| }
|
| }
|
| }
|
|
|
| Thanks,
|
| Jerry
|
|
Jan 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
829
by: Opa | last post by:
Hi, Does anyone know how to get a list of files for a given directory from a given url. I have the following, but get an error indicating that URI formats are not supported. System.IO.DirectoryInfo di di = new System.IO.DirectoryInfo("http://www.websitehere.com/files/"); System.IO.FileInfo rgFiles = di.GetFiles("*.jpg");
11
1969
by: Brett | last post by:
In Yahoo mail, I click the Inbox link and see my messages. If I view source, I don't have HTML which contains the URL of each message. The source HTML contains javascripting and framesets. This is different from what I am seeing. If I right click on a message link and select "copy shortcut", I can paste this link into my browser. This brings me to my message. If I view source, once again, it is javascript and framesets. How do I...
5
1797
by: Krustov | last post by:
<?php $dirname = "."; $dh = opendir($dirname); while ($file = readdir($dh)) { if (is_dir ("$dirname/$file")) { print ""; } print "$file<br>";
6
1748
by: JD | last post by:
Hi all, Can anyone tell me is there a way to get a list of file types either supported on the server or clients computer and bind it to a drop down list in C# Thanks Jonathan Dixon
0
3869
by: Brian Henry | last post by:
I want to pull my contact list (personal one) from the exchange server into a local text file. I know how to write stuff into a text file, just getting it from an exchange server is my problem. I've been looking at webdav as a solution to this, but i dont know much about how to use webdav or it with exchange server. Right now i'm working with VB.NET I found a sample project at...
0
3713
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
6
1447
by: nephish | last post by:
Hey there all. i have been looking to simplify my huge website that i wrote while learning php. now its a spaghetti mess. So, i wanted to simplify it. Now, i see the functionality that defining functions can give me. But what is the magic behind classes? i mean, the documentation i find. Most use the class Person as the example. So how would having a person class help me. It seems that i am writing more code than less because i am...
1
2425
by: iwdu15 | last post by:
hi, how can i get the icon associated with a certain file type? thanks -- -iwdu15
4
6217
by: AshishMishra16 | last post by:
HI friends, I am using the Flex to upload files to server. I m getting all the details about the file, but I m not able to upload it to Server. Here is the code i m using for both flex & for Struts: import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator;
5
1632
by: tshad | last post by:
I have the following class in my VS 2008 project that has a namespace of MyFunctions. ********************************* Imports System Imports System.Text.RegularExpressions Namespace MyFunctions Public Class BitHandling
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.