|
Hi,
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.
Regards
Sebastian
|
|
|
|
|
thanks for reply baut file system watcher i must give it one directory to watch it
i want get the name of the files on any where on computer
thanks again for reply
|
|
|
|
|
Okay, well, but isn't your drive a directory?
|
|
|
|
|
Watching an entire drive is not a good idea. The FSW starts to perform badly the more you have it watch.
He really doesn't have a solution to use since there is nothing that signals "Hey, there's a copy going on!".
|
|
|
|
|
The FSW, as bad as it is, is the only solution you have. There is no event or any signal that says there is a copy operation going on.
|
|
|
|
|
Hi Folks,
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 in advance for all and have a nice day.
|
|
|
|
|
|
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++)
{
listbox1.SetSelected(i, true);
sw.WriteLine(listbox1.SelectedItems[i].ToString());
}
sw.Close();
Hope this will help someone else. (of course you can personalize it like adding savefiledialog...)
Cheers, 
|
|
|
|
|
|
Hi, i have wrote a code to connect to FTP. But once connected, a DISCONNECT button will show. And when i click it, i wan it to end the connection.
CONNECT CODE
public bool Connect()
{
bool success = false;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + tbxServerAddress.Text + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(tbxUsername.Text, tbxPassword.Text);
reqFTP.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
WebResponse response = reqFTP.GetResponse();
if (response !=null)
{
success = true;
}
else
{
success = false;
}
}
catch (Exception ex)
{
MessageBox.Show("Error : Invalid User or Pass");
}
return success;
}
Btw am i coding the connect code the right way?
And how do i code the DISCONNECT method
|
|
|
|
|
|
It doesnt have the finalize method
btw when i upload a file, how do i use the current connection to upload instead of creating a new connection
|
|
|
|
|
|
but i cant use it.. it says
Finalize is protected and, therefore, is accessible only through this class or a derived class.
|
|
|
|
|
You can send the "close" command to the ftp server to quit the connection, or close the stream AFAIK.
|
|
|
|
|
Hi,
Can you tell me to develop Smart Card Application in C#.
|
|
|
|
|
|
Since the var keyword has been introduced for anonymous types I have noticed more and more code examples (and seen in my work) people using var rather than a defined type.
To my mind var should only be used when an anonymous type is being used and only then not instead of a defined type.
What are peoples thoughts? are you seeing a rise in the use of var?
|
|
|
|
|
If you give a novice programmer something to abuse, they will abuse it. Its about the first rule of computer programming.
The only place I have used var so far is in the return from a LINQ query, I see no reason to use it extensively. So in short, I agree with you.
|
|
|
|
|
I absolutely agree with you.
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...
Regards
Sebastian
P.S.: Had a big discussion here last week, if we should use it throughout the code or not...
|
|
|
|
|
What has been worrying me is more senior experienced programmers starting to do it.
Brought back horrible memories of VB6 variant <shudder>
|
|
|
|
|
|
Eddy Vluggen wrote: 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.
Regards,
Rob Philpott.
|
|
|
|
|
Since you're asking for opinions, here's mine.
I would not be opposed to seeing var when you are declaring a new something (especially when the type name is long). For example:
var cache = new Dictionary<string, LongTypeNameIWantToTypeJustOnce>();
as opposed to
Dictionary<string, LongTypeNameIWantToTypeJustOnce> cache = new Dictionary<string, LongTypeNameIWantToTypeJustOnce>();
which I either have to break up into multiple lines or have one really long line. Even if the line is not too long, the second way is still noisier than the first.
For the record, this is one of the things I like about the VB syntax (only needing to write the type once when declaring and "new"-ing a variable at the same time)
|
|
|
|
|
I agree, it is being abused. I never use var, and as I also never use Linq, I don't expect to.
|
|
|
|