I have been using ASP.NET for some time, but now I need to be able to create a quick program that sends out an email if a file exist. A batch file will be executing this file on a scheduled basis. What is the best way to write this. (By the way, I have the code to do this, I did it as an ASP.NET application, now I want to port it to an executable). I am using VS.NET 2003.
Thanks.

Creating an exe without using a Form
jocamp3
Thanks for all the help, this is great feedback!!
rfmfix
static void Main(string[] args)
{
SendMail();
}
I get this error:
An object reference is required for the nonstatic field, method, or property 'ConsoleApp.Class1.SendMail()'
Tamer2
truepantera
It's true that a console app is simpler, but console apps aren't meant to run nonstop without interruption. Just wanted to bring that up -- that's what services are for.
In any case, you must add a reference to your project for the System.Web.dll assembly in order to send email, and from there, add code that calls the Send method of the System.Web.Mail.SmtpMail class. I'm not sure where the SendMail method came from, but it's not provided by the .NET Framework.
MikeApplied
TimBemis
psilos2000
1. Are you creating the console app from Visual Studio or another text editor
2. Have you included a reference to the dll containing SendMail object
hopark16
Scott Swigart - MVP
In answer to your question about a console app "Page_Load", a console app has a <b>Main</b> function which is called when the app is executed, for example...
using System.Console;
class MyHello
{
static void Main()
{
WriteLine("This is a console hello");
}
}
In the <b>Main</b> you can initialise any object you wish to use.
Hope this helps
Paul Reith
Oliver 123
static void Main(string[] args)
{
MyConsoleApp myapp = new MyConsoleApp();
myapp.SendMail();
}
Or you can make SendMail() static and call it from Main() like you did:
public static void SendMail()
{
// send out mail
}
static void Main(string[] args)
{
SendMail();
}
-Ari
ladymuck