Attach form attachment to outlook message

A

andyoye

Below code is attached with a button on my infopath form. It does work (
auto populates "To:" and "Subject" based on form nodes) but how can I attach
the file to the message which is attached to attachment control to the form?

Thanks

public void Email_Clicked(object sender, ClickedEventArgs e)

{


XPathNavigator docFM = this.CreateNavigator();

string attachName = docFM.SelectSingleNode("/my:myFields/my:txtSubject",
this.NamespaceManager).Value;

XPathNavigator docFT = this.CreateNavigator();

string msgTo = docFT.SelectSingleNode("/my:myFields/my:EmailTo",
this.NamespaceManager).Value;

Outlook.Application outlookApp = new Outlook.Application();

Outlook.MailItem message =
(Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);

message.Subject = attachName;

message.To = msgTo;

message.Body = "This is a test.";

message.Display(false);

outlookApp = null;

}}
 
A

andyoye

Looks like I need message.Attachments.Add (sSource, object Type, object
Position, object DisplayName)

If I do:

String sSource = @"C:\abc.txt", it gets attached to the message.

How can I set "sSource" value bases on "attachName" form field?

String sSource = @"C:\ + attachName + .txt" ???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top