I am a junior level developer and I have a situation where a previous developer wrote an aspx page, named with a guid, so as not to be accidentally accessed by a user. Its function is to call stored procedures to get a list of recipients, and populate a DataTable. Then use NPOI.dll to export the dt to an excel workbook and email it to the recipient list. There are no controls in the front end, it's all triggered on page load. This page is called once a week by setting this page as the default page on the servers browser, and setting a job on the server to start the browser. All of this actually worked well for quite a while, however, now the client would like to remove the page from the site and use an alternate method to generate and send the weekly report. Here's my question. Can I compile this code-behind into an .exe application that can be called by a server job? Or is there a better way to approach this? Any recommendations and/or guidance would be appreciated!I have searched and could find no relevant discussions.
-
The accepted answer of creating a Console Application was all the help I needed. I was just unsure of what direction to take. Thanks Habib, this works like a charm. – Matthew Carr Jan 30 '15 at 11:40
2 Answers
You have to create a separate Console Application and move the code manually. It will involve copy/paste code from code behind to your Console app. Once your console app is done, then you can schedule the app to run weekly via Operating System Schedule tasks.
As a starting point copy the code from Page_Load
method to Main
method in the console app, You will also need to add the references for required dlls like NPOI.dll
. Once you are able to compile your console application successfully, then you can test it by sending out some test emails. That console app will give you an executable that you can schedule on a machine to execute ever week.
See: Schedule a task

- 219,104
- 29
- 407
- 436
I would Isolate the logic in a class library that could be called from the Web or by WinForms, because all it's doing is reading data from a table creating the excel file, then emailing it. That way, if the clients want more ways of producing the Excel workbook, the logic is isolated and ready to use elsewhere.

- 7,849
- 4
- 37
- 49