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.AppS ettings["e mail_from" ];
mail.Subject = strSubject;
mail.Body = strContent;
mail.BodyFormat = MailFormat.Html;
mail.Priority = MailPriority.High;
mail.To = strTo;
mail.Cc = strCc;
SmtpMail.SmtpServer = ConfigurationSettings.AppS ettings["e mail_serve r"];
try
{
SmtpMail.Send(mail);
}
catch (Exception ex)
{
while( ex.InnerException != null )
{
ex = ex.InnerException;
}
}
}
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.AppS
mail.Subject = strSubject;
mail.Body = strContent;
mail.BodyFormat = MailFormat.Html;
mail.Priority = MailPriority.High;
mail.To = strTo;
mail.Cc = strCc;
SmtpMail.SmtpServer = ConfigurationSettings.AppS
try
{
SmtpMail.Send(mail);
}
catch (Exception ex)
{
while( ex.InnerException != null )
{
ex = ex.InnerException;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Thanks.