Solved

access this function in multiple files

Posted on 2006-11-06
5
176 Views
Last Modified: 2010-04-16
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;
            }
      }
}
0
Comment
Question by:solraccheffy
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 50 total points
ID: 17886952
Not sure what caused the problem...

I'd make the method static so you don't need to create an instance of the helper class in each page:
public static void SendEmailOpen

If your helper class is called like 'Helper', you invokethe method:

Helper.SendEmailOpen(....)
0
 

Author Comment

by:solraccheffy
ID: 17889083
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.
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 17892470
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now