Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This Scenario: User copies large files to a local folder. I want to watch that folder and when a new file is dropped then go and copy it to Database, so later when coping is done I can actually use it in my application. ( A C# WinForms App). It would be awesome to also find a way to somehow get notified in the Application that hey copying the file to DB is finished and ready for use...

I am using C#.net, Windows... What solutions/architecture do you suggest for this? For example having a windows service running all the time watching that folder, when something copied goes and write it to DB ... then how about getting notified? MSMQ is something I can use? don't know much about it yet.

Thanks.

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

You have two seperate problems :

  • monitoring and copying data
  • notifying clients

Monitoring: and copying the data to the database is a process that you would want to have running in the background so you can start and stop it when needed independent of your application. I would suggest making that a windows service that uses the filesystem watcher. Mind the location of the files, the uploading application and the service both need access to that location.

An older article on this can be found here http://www.codeproject.com/Articles/18521/How-to-implement-a-simple-filewatcher-Windows-serv (things have changed since 2007)

notifying your application, does it need to be real time ? When the application starts does it need to know there are new files waiting ?

If the application needs to check when starting you could simple make a table where the service keeps track on the files it has processed and that your windows app can query to see if files are waiting. If the notification does not need to be real time you could trigger the check based on a timer and you would have a pretty simple solution.

If the notification needs to be real time you need other options.

SignalR mostly is used in web apps but I have seen it work in console apps and it is pretty simple to set up and easy to use. If you download signalR https://github.com/SignalR/SignalR in the samples there is a self hosted example that might get you up to speed. Make your service the messagehub and let client applications connect on startup. SignalR is pretty new and I have not seen a lot of people use it outside of a web app so it might be a risk trying this, but it should be fun :)

If you don't want signalR and stil need real time notifications you could look at:

  • have a status folder in your data folder, your service writes status files in this folder and you application watches this status folder via the fileSystem watcher, I like this because your app and the service are using the same technologies and it is always a good idea to keep the number of technologies and the number of different solutions as low as possibel.
  • let the service write to a message queue and have your app monitor that (overkill in my mind)
  • make your service and windows app like chat application using WCF broadcast messages. A sample to get you started : http://www.codeproject.com/Articles/19752/WCF-WPF-Chat-Application (way to much work in my mind)
share|improve this answer
add comment

You can do it in two ways: -

  1. If copying of files is being done through your application then you can write a piece of code that will send you an email for notification.

  2. If the user is not using the application for uploading the files then you can write a script that will be executed after every 30 minuts and read the folder in which the users are uploading the files and if a new file is found then either send you the notification or perform the required action on the file and notify you and the user.

Hope this helps.

share|improve this answer
add comment

If you are talking about notifying the application, not user, two ways of doing that comes onto my mind:

  1. Create and setup instance of System.IO.FileSystemWatcher, have your application working all the time (i.e. in system tray) and react as you only want to when files in directory change;
  2. Create a service that will be listening the directory and will do all the copying and communicate with the main application through pipes.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.