there is a class called System.IO.FileSystemWatcher. Using this class you can observe file actions on directory or file. If a file is copied the FileSystemWatcher will throw the event OnCreated. Problem is that you don't know if it is a newly created file or a copied file... but maybe it is a good point to start.
I made one prog with C# to list some query in a listbox control, and I want it to be saved to a file like *.txt or *.csv or ... anyway I just want to save my listbox content but I don't know how if someone can give me some tips.
Thanks for your reply but it does not what I expect to have. Maybe my question is not quiet clear so I'll explain first what I want to have.
So I have one listbox that I populate with a result of a calculation. Let's say the listbox contains 100 items.
What I need is to save those list items into a file (maybe I want them later even if I already closed the program for another process).
What you showed me is just the way how to write into a file but not how to retrieve all value of the list and save them into a file.
This is what I want.
But, fortunately, I know now how to save the listbox contents :
1. I count the number of items : listbox1.Items.Count;
2. recursively set each Items selected : listbox1.SetSelected(i, true);
and StreamWriter each selected Items directly.
for example :
int number = listbox1.Items.Count;
StreamWriter sw = new StreamWriter(@"C:\list.csv");
for (int i = 0; i < number; i++)
Hope this will help someone else. (of course you can personalize it like adding savefiledialog...)
As I see it, every developer must be aware what he/she is doing. He has to know about the types etc. he is using etc. Using a paradigma like "Uh I don't know what the return type of this method is, but hey who cares, the compiler will do it for me" is not the way I agree with.
So in my opinion the excessive use of "var" makes the code difficult to read, you always have to search for the last assignment...
As far as I know, var was introduced only for the use with LINQ, but as you already said, it will be abused...
P.S.: Had a big discussion here last week, if we should use it throughout the code or not...
Resharper keeps reminding me that I should use "var" instead of the type-safe declaration
I know! Well, they've got it wrong. I hate the use of this subversive keyword. Fair dos for LINQ but no place elsewhere. Presumably you can tell Resharper not to do that, but I can't be bothered to wade through all the options pages. It does alsorts of things I don't care for - breaking my lines up, trying to use 'object initializers' to squeeze everything onto the construction line, putting space between casts etc.
It should chill out a bit.
Last Visit: 31-Dec-99 19:00 Last Update: 11-Dec-23 9:45