Link to home
Start Free TrialLog in
Avatar of solraccheffy
solraccheffy

asked on

access this function in multiple files

In my c# web app, I have a bunch of aspx pages that I want to add error catching, try catch and finally code and anytime the catch exception is invoked I want to call a common function(send an email) I have in my helper.cs file - code below.
The problem is I dont know how to access this function that is in my class, the helper file from my aspx.cs file. I dont want to copy this code accross all my aspx.cs file.

Assistance would be appreciated.

public void SendEmailOpen( string strSubject, string strContent, string strTo, string strCc )
{
      //send email to the admins - get admin list from web.config
      MailMessage mail = new MailMessage();
      
      mail.From = ConfigurationSettings.AppSettings["email_from"];
      mail.Subject = strSubject;
      mail.Body = strContent;
      mail.BodyFormat = MailFormat.Html;
      mail.Priority = MailPriority.High;

      mail.To = strTo;
      mail.Cc = strCc;

      SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["email_server"];
      try
      {
            SmtpMail.Send(mail);
      }
      catch (Exception ex)
      {
            while( ex.InnerException != null )
            {                              
                  ex = ex.InnerException;
            }
      }
}
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of solraccheffy
solraccheffy

ASKER

Thanks for the reply, I changed to the static method as you described, but in my .cs file when I specify the line as you described to invoke....the autotype does not kick in....I typed in Helper. and nothing is coming up, is there something else I need to do to reference/invoke this method?

Thanks.
If your class is in a different project you need to import it ("using" keyword) and may be to add a reference to the project from project references.