?
Solved

access this function in multiple files

Posted on 2006-11-06
5
Medium Priority
?
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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