views:

50

answers:

1

I have a folder with .txt files in it. How can i make my menuitem get those .txt files and put the filenames in the menuitem, so that it creates a list of all .txt files in that folder.

So when i put a .txt in the folder the program automatically creates the menu item.

Does someone knows how to do this, or perhaps an example?

+1  A: 

Unless you're using ASP.Net, you're looking for the FileSystemWatcher and Directory classes.

Basically, you need to call Directory.GetFiles and loop through the results creating MenuItems.
Then, handle the FileSystemWatcher events and either rebuild the menu from scratch (simpler) or update the appropriate item (faster)

SLaks
Can you give an example?
PandaNL
@PandaNL, this is actually a good assignment for you to learn how to using WinForms and handling events. There are plenty of FileSystemWatcher examples and MenuItem examples. I do suggest that you use the newer MenuStrip.
AMissico
Exactly. If you cannot figure out how to do this using the `FileSystemWatcher` and `Directory` classes, you should take a basic programming course.
SLaks