By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,610 Members | 1,613 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,610 IT Pros & Developers. It's quick & easy.

Attach form attachment to outlook message

P: n/a
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.Ol ItemType.olMailItem);

message.Subject = attachName;

message.To = msgTo;

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

message.Display(false);

outlookApp = null;

}}
Jul 23 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" ???


"andyoye" <an*****@nospam.comwrote in message
news:Oz**************@TK2MSFTNGP03.phx.gbl...
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.Ol ItemType.olMailItem);

message.Subject = attachName;

message.To = msgTo;

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

message.Display(false);

outlookApp = null;

}}


Jul 23 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.