[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

access this function in multiple files

Posted on 2006-11-06
5
Medium Priority
?
184 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
3 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 150 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 30

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

831 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