Search code examples
c#.netemailinfopathinfopath-2007

Change email subject


I am using InfoPath 2007

I have some code written in the form that will put a form into an e-mail. I would like to alter the subject of that e-mail so that I can display a fixed piece of text as well as the results from the data in one of the form fields;

var objEmail;
objEmail = Application.ActiveWindow.MailEnvelope;
objEmail.To = x@y.com;
objEmail.Subject = "extras request";
objEmail.Visible = true;

I want to alter the line

objEmail.Subject = "extras request";

to include display the results from the data in the form field labNO but I am not sure how ?


Solution

  • var navigator = MainDataSource.CreateNavigator();
    
    var labNO = navigator.SelectSingleNode(xpath, this.NamespaceManager).Value;
    
    objEmail.Subject = string.Format("extras request {0}", labNO);
    

    The variable 'xpath' is a string which points to the labNO field i.e. "/my:myFields/my:labNO". You can copy it by right-click'ing the field - Copy XPath.

    If the labNO field is within an external DataSource, you'd use this instead:

    var navigator = DataSources["DataSourceName"].CreateNavigator();