Possible Duplicate:
Writing a Windows system tray application with .NET
I want to develop a tray application. What this should do is it must keep looking for recently modified files.. once a file is get caught it a copy of that file to the web server. Therefore, user will be able to login to the website and later on user will be able to download those backing up files. what i want to know is how do i develop the tray application? Do i have to write a windows service for that? If so, i need a tray application to control the service (tray application must have sfunctionalities to start and stop service [Backup service], An option to choose the file extensions) I'm using c#. Thanks a lot in advance.
Sounds pretty straightforward.
Create a basic WinForms app. The app's main window should start "minimized" and should not show in the taskbar. But, it should have a "NotifyIcon" component, which allows the app to show in the system tray. Double-clicking the NotifyIcon would restore the window, show the window in the taskbar and hide the NotifyIcon until the window is minimized or closed again.
This application can do the file watching on its own, or it can edit the configuration used by a Windows service; either way would work. Either way, you need to set up a FileSystemWatcher (or several of them) that monitors files in the directories the user wants you to check. When a FileSystemWatcher sees a file change, it'll fire an event that you can handle by performing the upload to the web server.
Just as an aside to the whole design; if you're implementing an online backup system (which it appears that you are), I would make sure that the user has access to several past iterations of the file, in case they want to restore a previous version. You should also have virus-checking; the last thing a user would need is for a virus to wreck their files AND for your backup system to have backed up the wrecked files.
I personally wouldn't make it like a Windows Service
, but would choose a simple application that "lives" on behind of system. It's easier to maintain and update, uninstall from the client (on his request). In short, for something simple I wouldn't go for Windows Service.
I would add a sys-tray component, with some menus. You can have a look at WPF NotifyIcon from Philipp Sumi.
One of menu items can have an item that registers executable to run on startup of the OS. You can achieve that with kind of code:
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
Assembly curAssembly = Assembly.GetExecutingAssembly();
key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
If for some reason, cause it's not very clear from your post, your application, indeed, goes to manage some serious amount of data on considerable production environment, go for WindowsService and manage all related to it stuff.
Hope this helps.