Kype

Hello,

I try to add an InfoPath form as a mail attachment with vsto.
I create my mail with this code :
Outlook.Application outlook = new Outlook.ApplicationClass();
Outlook.MailItem Email = (Outlook.MailItem)outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

Then I try :
Email.attachments.add() but :
1) I don't know how to get the form. Should I use thisXdocument
2) what arguments should I use in the method add (object Source, object Type, object Position, object DisplayName)

I simply tried with
Email.Attachments.Add("test", Outlook.OlAttachmentType.olByValue, 1, "attachment");
but I get the following error :

L'exception System.Runtime.InteropServices.COMException n'a pas ete geree par le code utilisateur
Message="Impossible de trouver ce fichier. Verifiez que le chemin d'acces et le nom du fichier sont corrects."
Source="Microsoft Office Outlook"
ErrorCode=-1905852414
StackTrace:
a Microsoft.Office.Interop.Outlook.Attachments.Add(Object Source, Object Type, Object Position, Object DisplayName)
a InfoPathProject2.InfoPathProject2.CTRL1_5_OnClick(DocActionEvent e)
a Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)




Thank you for your help :D

Kype



Re: Visual Studio Tools for Office Adding InfoPath Form as Mail Attachment

Ade Miller - MSFT

This isn't really a VSTO question. You would be much better off asking experts in the Outlook programming or Office programming/PIA communities about this.

General programming issues: outlook.vba newsgroup

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.office.developer.outlook.vba&lang=en&cr=US

Working with the Office Primary Interop Assemblies (PIA): office.developer.automation newsgroup

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.officedev&lang=en&cr=US

Office Automation: office.developer.automation newsgroup

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.office.developer.automation&lang=en&cr=US

VSTO is primarily about programming from within Office applications, rather than automating them externally.

Thanks,

Ade






Re: Visual Studio Tools for Office Adding InfoPath Form as Mail Attachment

Kevin Farley

Kype -

There is already a "Send to mail" feature in InfoPath and you can also trap this event in the form submit event handler.

From an Outlook perspective, the InfoPath form is simply an Xml file that would be an ordinary attachment, so you would have to force a save of the InfoPath form to a path and pass this path to the Outlook interface.

No Outlook interface is required if you simply use the InfoPath features of submit behavior as mail where you can also attach any other Outlook integration in your code within this event handler.

kjf





Re: Visual Studio Tools for Office Adding InfoPath Form as Mail Attachment

Kype

Thank you for your answers.
In fact my goal was to open an Outlook client to allow the user to choose the receiver with the InfoPath form in attachment.
So using the InfoPath feature implies you already know who you want to send the mail.
That's why I tried with the Outlook perspective, but there are too many security problems, only if you just want to save the form.
The solution I finally implemented uses the mailenvelope object :
function CTRL1_5::OnClick(eventObj)
{
var mail = XDocument.View.Window.MailEnvelope;
mail.Subject = getNodeValue(xmlTitle);
mail.Visible = true;
}
This opens an Outlook interface and allows the user to change the "To" field.
The form is also visible in the mail. The limitation here is that there are only 4 or 5 properties for this object, and you can't change the name of the attachment for example.

Kype






Re: Visual Studio Tools for Office Adding InfoPath Form as Mail Attachment

AmrendraKumar

To send attachments I use

mailItem.Attachments.Add(currentNode.Name, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, 1, "picture 1");

Hope that helps.