1

I need to to be able to detect a .csv file which will be dropped on an FTP Server. When the file is transferred it should trigger code to read the file and then upload all the information from the .csv file to a SQL Server. After the file is transferred it should then run a few other functions which will essentially validate what is uploaded and perform some calculations.

In the ideal sense the functions should execute once the file is dropped(run in the background without any human interaction). I've found where FileWatcher was used in C# applications but not in MVC.

Does anyone have any examples where this is accomplished in Asp.net MVC 5 or a better solution to this?

Thanks.

user2806570
  • 821
  • 2
  • 12
  • 25
  • 4
    Why do you want to implement this in your ASP.NET MVC 5 application? Wouldn't it be better to write a new application (for example a windows service) that runs on the same machine as the MVC application. This windows service could watch the folder with the FileWatcher and transfer the data to the database. – Shamshiel Nov 08 '17 at 12:28
  • Thought I'd make it easier for it to all work within one app. Also if it was written as a windows service how would i trigger the processes on the MVC application after the transfer of the data to the database? – user2806570 Nov 08 '17 at 12:47
  • What process do you mean? What exactly should the MVC application do? – Shamshiel Nov 08 '17 at 12:57
  • It has to take the data from the csv file and run it against other tables and validations which will flag exceptions from those validations and provide exception details which then fires of an email with a link to an exception view within the mvc app where once all the exceptions are "fixed" then reruns the validations again and so forth until there are no exceptions and all the data is corrected – user2806570 Nov 08 '17 at 13:10
  • What you could do is send the file asynchronous (for example with ajax) to a controller method and process it there. You don't need to transer it via FTP. After the file is processed you can show the results to the user. – Shamshiel Nov 08 '17 at 13:19
  • Unfortunately the ftp server drop is a requirement by the customer so it has to be that way. – user2806570 Nov 09 '17 at 05:26

1 Answers1

1

There is a C# sample for the FileSystemWatcher here. But a web application running in IIS is not the best platform for a long-running thread. IIS will kill your threads periodically as it performs application pool recycling and then try to recreate them sometimes with unexpected results. After some time not receiving any web request, IIS goes to sleep and your thread will also stop working. When changing IIS configuration to force it not to do these things, memory leaks and other mean things may occur. Years ago, we've worked with Quartz.Net and faced all sorts of issues (suddenly not running, raising memory exceptions, etc) till we moved the scheduler thread from an ASP.Net web application to a Windows Service and worked fine. I don't think IIS is thought for doing what you want to do.

derloopkat
  • 6,232
  • 16
  • 38
  • 45