Save form and Attach to email

L

Lori G

I am trying to write a code in JScript that will save a form in a
location, then attach that form to an email.

I have tested the email part, and it works, and I have tested the
SaveAs part, and it works. The problem is combining them so that one
button will do both functions. Below is the code I have so far:
function CTRL4_5::OnClick(eventObj)
{
//Save Message first
XDocument.SaveAs("C:\\Form1.xml");

// Create a new message and fill all its fields
var iMsg = new ActiveXObject("CDO.Message");
var s = XDocument.DOM.selectSingleNode("//my:field1").text + "\r\n" +
XDocument.DOM.selectSingleNode("//my:field2").text + "\r\n" +
XDocument.DOM.selectSingleNode("//my:field3").text
iMsg.To = "(e-mail address removed)";
iMsg.From = "(e-mail address removed)";
iMsg.Subject = "Testing Email From InfoPath";
iMsg.TextBody = s;

//Add the Attachment
iMsg.AddAttachment("C:\\Form1.xml");

//Set SMTP server
iMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "smtp.mydomain.com";
//Use the SMTP over the network for sending method
iMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")
= 2;
//Make persistent
iMsg.Configuration.Fields.Update();

//Send the message
iMsg.Send();


When I attempt to click the button, it goes through the save process
normally, then it gives me the following error: "The process cannot
access the file because it is being used by another process." When I
attempt to debug the break point is at line 38 (the attachment).

It appears that the SaveAs function is locking the file and won't let
me attach it. The form is fully trusted and installed when testing. Is
there something else that I need to add? I am fairly new to JScript and
having to basically teach myself, so any assistance will be great!
 

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