开发者

How to send report via email monthly automatically in asp .net

开发者 https://www.devze.com 2023-03-02 21:23 出处:网络
can any one send me solution on this problem . Here i want to send crystal report that is automatically generated and attach to mail . Here report can be generated monthly automatically with asp .net

can any one send me solution on this problem . Here i want to send crystal report that is automatically generated and attach to mail . Here report can be generated monthly automatically with asp .net along with c# Lang. Send me solu开发者_开发百科tion for this.


I agree with the above recommendations to use a Scheduled task (console app), but nobody has mentioned that you cannot schedule a web-page to be executed on a schedule like that without an external utility that basically schedules an HTTP-request. Not to mention that a report that needs to be executed monthly typically cannot finish executing before the limited (default) response timeout anyways. That's what it's a bad idea. However, in the interest of answering the question, I will say that you can write a simple VBS or C#(.NET) console app to make an HttpRequest to your webserver and send the result in an email. Then add that console app to the windows task scheduler to execute monthly. Now your ASP.NET application is sending monthly emails. Don't forget that your C# console application will need to deal with login and authentication (if necessary).

The alternative is to (unreliably) create a timer (background process) within your global.asa (Application scope) when the HttpApplication.Init method is called. The reason this is unreliable is that the Application object can be recycled at any time, and may not even be running if no requests have been made to this application in a while. In addition, if you have a web-farm environment, each server (and each server process in a web-garden scenario) runs its own instance of your HtppApplication object. They may even be overlapping within the same process space while one is being garbage collected.


You can use the any of the following:

1. set "windows task scheduler" to schedule an .vbs file that triggers an "asp.net page or webservice" to run and do your logic once in a month (Recommended).

2. Create a "windows service" project and set a timer within its onstart event.(windows service creation only available in professional/Ultimate versions of visual studio, but editing and compilation can be done in other versions) 

Since the logic should be done once in a month the step 1 is recommended.

Please see the steps to create the .vbs file that calls your asp.net page/web service

  1. Open notepad and copy the following code in it and save

    'Declare variables
    Dim objRequest
    Dim URL
    
    Set objRequest = CreateObject("Microsoft.XMLHTTP")
    
    'Put together the URL link appending the Variables.
    URL = "http://computerName/VirtualDirectoryName/Logic.aspx"
    
    'Open the HTTP request and pass the URL to the objRequest object
    objRequest.open "POST", URL , false
    
    'Send the HTML Request
    objRequest.Send
    
    'Set the object to nothing
    Set objRequest = Nothing
    
    1. change the extension from ".txt" to ".vbs"

    2. Create a new schedule in windows "Task Scheduler" and point the newly created sample.vbs file which will call the page where your logic is written (http://computerName/VirtualDirectoryName/Logic.aspx) and edit the settings to run once in a month.


To generate monthly automatically use Windows Services

0

精彩评论

暂无评论...
验证码 换一张
取 消