Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This file contains functions for data validation and form-level events.
- * Because the functions are referenced in the form definition (.xsf) file,
- * it is recommended that you do not modify the name of the function,
- * or the name and number of arguments.
- *
- */
- // The following line is created by Microsoft Office InfoPath to define the prefixes
- // for all the known namespaces in the main XML data file.
- // Any modification to the form template files made outside of InfoPath
- // will not be automatically updated.
- //<namespacesDefinition>
- XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-11-19T14:53:38"');
- //</namespacesDefinition>
- function butt_createEmail::OnClick(eventObj)
- {
- emailView("view1")
- }
- function emailView(strView)
- {
- //get the users temporary folder
- var objFSO = new ActiveXObject("Scripting.FileSystemObject");
- var strTempPath = objFSO.GetSpecialFolder(2);
- //load the form XML
- var strXML = XDocument.DOM.xml
- var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
- xmlDoc.async = false;
- xmlDoc.validateOnParse = false;
- xmlDoc.loadXML(strXML);
- //load the view XSL
- var xslDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
- xslDoc.async = false;
- xslDoc.validateOnParse = false;
- xslDoc.load(strView + ".xsl");
- //generate the HTML transform
- var strHTMLTransformed = xmlDoc.transformNode(xslDoc);
- var htmlDoc = new ActiveXObject("htmlfile");
- htmlDoc.write(strHTMLTransformed);
- //obtain a clean string of the solution path
- var uriPath = XDocument.Solution.URI.replace(new RegExp("%20","g"), " ");
- uriPath = uriPath.replace("file:///","");
- uriPath = uriPath.replace("manifest.xsf","");
- //create an outlook email
- var appOutlook = new ActiveXObject("Outlook.Application");
- var objMailItem = appOutlook.CreateItem(0);
- objMailItem.BodyFormat = 1;
- //locate images in the HTML and update image paths / store base64
- var myImages = htmlDoc.images;
- var re;
- for(var i = 0;i < myImages.length ;i++)
- {
- //determine the type of image (reference or inline)
- re = new RegExp("msoinline","ig");
- if (re.test(myImages(i).src) != true)
- {
- //reference images can be dealt with as normal image files and are in the 'cache' folder.
- var imgSource = uriPath + myImages(i).nameProp;
- }
- else
- {
- //inline images are base64 embedded images and need to be extracted first
- //we create an in memory xml document to store the Base64 and then convert it to binary
- //using an ADODB.Stream
- var strBase64 = myImages(i).attributes("xd:inline").value;
- var base64xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
- base64xmlDoc.async = false;
- var nodeNew = base64xmlDoc.createElement("imageFile");
- nodeNew.dataType = "bin.base64";
- nodeNew.text = strBase64;
- //convert the Base64 into a binary file
- var adodbStream = new ActiveXObject("ADODB.Stream");
- adodbStream.type = 1;
- adodbStream.open();
- adodbStream.write(nodeNew.nodeTypedValue);
- adodbStream.savetoFile(strTempPath + myImages(i).nameProp + ".bmp",2);
- adodbStream.close();
- var imgSource = strTempPath + myImages(i).nameProp + ".bmp";
- //we now want the HTML to use the saved binary file as the img and not the inline.
- strHTMLTransformed = strHTMLTransformed.replace("msoinline/" + myImages(i).nameProp, myImages(i).nameProp + ".bmp");
- myImages(i).attributes("xd:inline").value = '';
- }
- //finally we add the actual image file to the email as an attachment so it will reference correctly.
- objMailItem.Attachments.Add(imgSource,1,0,"");
- }
- //set the HTML of the email body
- var strHTMLTransformed = htmlDoc.documentElement.outerHTML;
- objMailItem.HTMLBody = strHTMLTransformed;
- //and display the final product
- objMailItem.Display();
- }
Advertisement
Add Comment
Please, Sign In to add comment