Sending an InfoPath 2003 form to people who don’t have the client
February 7, 2007
I needed to send the completed (ie approved) form, read-only, to the company who took care of the orders made in an InfoPath 2003 form. The form is stored in a SharePoint forms library, but the receiving company didn’t have access to this SharePoint site. 2007 would be sweet, but I can’t use that. Hmmm… how to do?
I created a web service, which the form, once approved, sent an email through (all stages in the workflow before approval used the ordinary data connection to the SharePoint forms library).
The web service receives the xml document from InfoPath, via the normal web service data connection available. The web service extracts the filename (stored as a secondary data source inside the form) and makes an html document out of the xml and xsl combined, which then can be viewed on any computer with an internet browser.
There’s one big-ass downside with this though. The xsl file has to be extracted from the infopath form and then edited a little to remove not-supported functions and so on, or else you’ll se some nasty error messages when opening the form in the browser. So if the form has undergone some major changes, you need to re-extract the xsl-file and put it somewhere where the web service can access it, which in my case is in the web service root directory.
Here’s the code:
public string InfoPathMailer(XmlDocument xmlDoc)
string filename = GetFileName(xmlDoc);
Stream stream = new MemoryStream();
XslCompiledTransform xslTransform = new XslCompiledTransform();
xslTransform.Transform(xmlDoc, null, stream);
stream.Position = 0;
MailSender m = new MailSender("yourmailserver.net", "email@example.com", "firstname.lastname@example.org", "New End User Request", "Do not reply to this address", filename, stream);
private string GetFileName(XmlDocument xmlDoc)
string infoPathNamespacePrefix = "my";
string infoPathNamespaceURI = @"http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-13T10:36:39";
XmlNamespaceManager namespaceMngr = new XmlNamespaceManager(xmlDoc.NameTable);
XmlNode node = xmlDoc.SelectSingleNode("//my:Filename", namespaceMngr);
string s = node.InnerText;
s = s.Replace("xml", "html");
And here’s the code for the class MailSender:
public class MailSender
//Constructor for attachment as stream
public MailSender(string server, string sender, string receiver, string subject, string body, string filename, Stream stream)
smtpServer = server;
mail = new MailMessage(sender, receiver, subject, body);
Attachment attachment = new Attachment(stream, filename, MediaTypeNames.Text.Html);
public void Send()
SmtpClient client = new SmtpClient(smtpServer);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
Hopefully this can help someone out there. Good luck!