<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Bernhard&#039;s SharePoint</title>
	<atom:link href="http://benny56sp.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://benny56sp.wordpress.com</link>
	<description>Daily life around SharePoint.</description>
	<lastBuildDate>Sun, 20 Mar 2011 19:22:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='benny56sp.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Bernhard&#039;s SharePoint</title>
		<link>http://benny56sp.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://benny56sp.wordpress.com/osd.xml" title="Bernhard&#039;s SharePoint" />
	<atom:link rel='hub' href='http://benny56sp.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How to remove content type associated workflows and status fields.</title>
		<link>http://benny56sp.wordpress.com/2010/03/15/how-to-remove-content-type-associated-workflows-and-status-fields/</link>
		<comments>http://benny56sp.wordpress.com/2010/03/15/how-to-remove-content-type-associated-workflows-and-status-fields/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 18:05:29 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ContentType]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=98</guid>
		<description><![CDATA[Usually I deploy my SharePoint applications via SharePoint solutions. I also use FeatureReceivers written in C# to initialize webs, lists and more to keep things consistant. When associating workflows with content types or lists a workflow status field is automatically generated and attached to the target list and default view. Doing this programmatically, for example [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=98&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Usually I deploy my SharePoint applications via SharePoint solutions. I also use FeatureReceivers written in C# to initialize webs, lists and more to keep things consistant.</p>
<p>When associating workflows with content types or lists a workflow status field is automatically generated and attached to the target list and default view. Doing this programmatically, for example by a FeatureReceiver, it might happen that status fields are added while creating a workflow association, but will not be removed in case of buggy code.</p>
<p>To cleanup the application you need to call a method like below:</p>
<p><pre class="brush: csharp; wrap-lines: false;">
RemoveSiteContentTypeAssociation(site, &quot;My workflow title&quot;);
</pre></p>
<p>Site content types are mighty SharePoint elements. They can be inherited to child content types und used in lists. When you attach a workflow to a content type a lot of children and list might be influenced. So cleaning up your site collection can be tricky and time consuming.</p>
<p>The following method does the job. It crawls through your site collection finds all target workflow associations in webs, subwebs, content types and lists and finale removes all workflow status fields from the lists and the associations of course. Result: your workflow is completely removed from the site collection.</p>
<p>If you suggest a better method let me know.</p>
<p><pre class="brush: csharp; wrap-lines: false;">

public static void RemoveSiteContentTypeAssociation(SPSite site, string associationName)
{
    SPWeb rootWeb = site.RootWeb;
    SPWorkflowAssociation association = null;
    Console.WriteLine(&quot;Removing site contenttype workflow association '{0}'.&quot;, associationName);

    // Remove all site content type workflow associations
    foreach (SPContentType ctype in rootWeb.ContentTypes)
    {
        // Remove site content type workflow association
        association = ctype.WorkflowAssociations.GetAssociationByName(associationName, rootWeb.Locale);
        if (association != null) ctype.RemoveWorkflowAssociation(association);
    }

    // Remove list content type workflow associations
    foreach (SPWeb web in site.AllWebs)
    {
        // Since we plan to modify some lists later we can not use the standard web.Lists collection
        System.Collections.Generic.List&lt;Guid&gt; lists = new System.Collections.Generic.List&lt;Guid&gt;();
        foreach (SPList list in web.Lists) lists.Add(list.ID);

        // Check all lists
        foreach (Guid listId in lists)
        {
            // Get list
            SPList list = web.Lists[listId];

            // Remove all matching list content type associations
            foreach (SPContentType ctype in list.ContentTypes)
            {
                // Remove list content type workflow association
                association = ctype.WorkflowAssociations.GetAssociationByName(associationName, web.Locale);
                if (association != null) ctype.RemoveWorkflowAssociation(association);
            }

            // Find all workflow status fields in the list
            System.Collections.Generic.List&lt;Guid&gt; fields = new System.Collections.Generic.List&lt;Guid&gt;();
            foreach (SPField field in list.Fields)
            {
                // Check field and save Guid on match
                if (field.Type == SPFieldType.WorkflowStatus &amp;&amp; field.Title == associationName) fields.Add(field.Id);
            }

            // Remove the fields from the list
            foreach (Guid fieldId in fields)
            {
                SPField f = list.Fields[fieldId];   // Get the status field
                f.ReadOnlyField = false;            // Flag read/write
                f.Update(true);                     // Update first otherwise the field cannot be deleted
                f.Delete();                         // Now delete
            }

            // Save modified list in database
            list.Update();
        }
        web.Dispose();
    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=98&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/03/15/how-to-remove-content-type-associated-workflows-and-status-fields/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
		<item>
		<title>How to transform InfoPath 2007 form data into a Word 2007 document – Part 3</title>
		<link>http://benny56sp.wordpress.com/2010/03/06/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-%e2%80%93-part-3/</link>
		<comments>http://benny56sp.wordpress.com/2010/03/06/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-%e2%80%93-part-3/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 22:46:51 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[InfoPath 2007]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Word 2007]]></category>
		<category><![CDATA[Xslt]]></category>
		<category><![CDATA[extension object]]></category>
		<category><![CDATA[formatString]]></category>
		<category><![CDATA[InfoPath]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=87</guid>
		<description><![CDATA[Part1 of &#8220;How to transform InfoPath 2007 form data into a Word 2007 document&#8221; gives an overview on creating a Word 2007 document based on a Word template and InfoPath data. The final transformation is done by using the xslt stylesheet InfoPath2Word.xslt. The stylesheet expects culture dependend formatted InfoPath data where necessary. Normally date, time and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=87&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a title="Part1" href="http://wp.me/pNM5S-M" target="_blank">Part1</a> of &#8220;How to transform InfoPath 2007 form data into a Word 2007 document&#8221; gives an overview on creating a Word 2007 document based on a Word template and InfoPath data. The final transformation is done by using the xslt stylesheet <strong><em>InfoPath2Word.xslt.</em></strong></p>
<p>The stylesheet expects culture dependend formatted InfoPath data where necessary. Normally date, time and number fields are culture dependend. <a title="Part2" href="http://wp.me/pNM5S-1a" target="_blank">Part2</a> shows how to transform InfoPath data into culture formatted InfoPath data. The xslt stylesheet <strong><em>InfoPathFormat.xslt</em></strong> calls the function <strong><em>xdFormatting:formatString($value, $type, $options)</em></strong> to output formatted values.</p>
<p>The <strong><em>formatString</em></strong> function is written in C# and passed to the xslt processor as an xslt extension object. I thought it would be good idea to to post about the formatString function separately, because it is also a key function which might be useful in other contexts. Please refer to <a href="http://wp.me/pNM5S-1j" target="_blank">Implement InfoPath formatString function for customized form data conversions</a> to get a C# listing and see how to use xslt extensions objects.</p>
<p><strong>The final step</strong></p>
<p>Now since all key modules are explained and available it is time to combine them by packing them into the class <strong><em>MyLib.InfoPath.WordConverter</em></strong>. Below please find the C# listing.</p>
<p>I use the WordConverter inside an InfoPath form. I added a button control to the form. When clicked, the event handler first checks whether a pdf file is attached to the form. It is assumed that a pdf file is a manually signed document. If not, a word document is created and attached.</p>
<p><strong><em>Example on how to use the WordConverter</em></strong></p>
<p><pre class="brush: csharp; wrap-lines: false;">
public void btnCreateContract_Clicked(object sender, ClickedEventArgs e)
{
    // Get navigators
    XPathNavigator navRoot = this.MainDataSource.CreateNavigator();
    XPathNavigator navContract = navRoot.SelectSingleNode(&quot;/ns1:contract/ns1:file&quot;, this.NamespaceManager);

    // Create word document only, if no signed contract already attached.
    if (FileAttachment.IsPdf(navContract))
    {
        // Pdf attachment already exists
    }
    else
    {
        // Field is either empty or contains an unsigned document
        string viewPath = &quot;view1.xsl&quot;;        // The view1 contains all the field formatting
        string dotxPath = &quot;contract.dotx&quot;;    // Word template for contract
        string docxFilename = &quot;contract.docx&quot;;    // Filename of the resulting word document

        using (Stream viewStream = this.Template.OpenFileFromPackage(viewPath))
        {
            using (Stream dotxStream = this.Template.OpenFileFromPackage(dotxPath))
            {
                FileAttachment.DeleteNillableAttribute(navContract);
                string wordAttachment = WordConverter.CreateWordDocument(navRoot, viewStream, dotxStream, docxFilename);
                navContract.SetValue(wordAttachment);
            }
        }
    }
}
</pre></p>
<p><strong>Conclusion</strong></p>
<p>The intension of this series of 3 posts was to show which steps are necessary to convert InfoPath form data to a rich Word document in cases where an electronical form is not useful, for example where signable paper documents are needed.</p>
<p>To keep things easy the Word document is based on a Word template with an embedded xml structure. The structure, which is actually a xml schema, is used by both the Word template and the InfoPath template. The default InfoPath view contains all the culture dependend formatting information to create the final Word document. In my case, the final document is programmatically attached to the InfoPath form and stored in a SharePoint form library. Now I can query form data, associate workflows and benefit from a convenient document management.</p>
<p><strong><em>MyLib.InfoPath.WordConverter</em></strong></p>
<p><pre class="brush: csharp; wrap-lines: false;">
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;

namespace MyLib.InfoPath
{
    public static class WordConverter
    {
        /**************/
        /* Properties */
        /**************/

        public static string InfoPath2WordStyleSheet { get { return GetFullResourceName(&quot;InfoPath2Word.xslt&quot;); } }
        public static string InfoPathFormatStyleSheet { get { return GetFullResourceName(&quot;InfoPathFormat.xslt&quot;); } }

        /**********************/
        /* CreateWordDocument */
        /**********************/

        /// &lt;summary&gt;
        /// Create a Word 2007 document from a Word template containing customXml tags
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;infoPathForm&quot;&gt;InfoPath form&lt;/param&gt;
        /// &lt;param name=&quot;viewStream&quot;&gt;An InfoPath view (xsl-file), which contains all field formatting templates&lt;/param&gt;
        /// &lt;param name=&quot;dotxStream&quot;&gt;The word template in which the data are to be inserted&lt;/param&gt;
        /// &lt;param name=&quot;docxFilename&quot;&gt;Filename of the resulting word document&lt;/param&gt;
        /// &lt;returns&gt;a base64 string which contains the InfoPath attachment encoded word document&lt;/returns&gt;
        public static string CreateWordDocument(XPathNavigator infoPathForm, Stream viewStream, Stream dotxStream, string docxFilename)
        {
            // Create a new word document from word template
            using (MemoryStream docxStream = new MemoryStream())
            {
                // Copy template
                CopyStream(dotxStream, docxStream);

                // Open template, convert it to a document and merge document wizh InfoPath form data
                using (WordprocessingDocument docx = WordprocessingDocument.Open(docxStream, true))
                {
                    // Change type from template to document
                    docx.ChangeDocumentType(WordprocessingDocumentType.Document);

                    // Fill template by formatted InfoPath form data
                    FillDocument(docx, FormatInfoPathForm(infoPathForm, viewStream));

                    // Save all
                    docx.Package.Flush();
                }

                // Return base64 encoded string of the word document
                docxStream.Seek(0, SeekOrigin.Begin);
                return FileAttachment.ToBase64String(docxFilename, docxStream);
            }
        }

        /******************/
        /* Private methods */
        /******************/

        private static string GetFullResourceName(string resourceName)
        {
            string [] names = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            foreach (string name in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (name.EndsWith(resourceName)) return name;
            }
            throw new FileNotFoundException(&quot;Resource file not found&quot;, resourceName);
        }
        private static void CopyStream(Stream input, Stream output)
        {
            int bufsize = 1024;
            byte[] buffer = new byte[bufsize];
            int bytes;

            while ((bytes = input.Read(buffer, 0, bufsize)) &gt; 0) output.Write(buffer, 0, bytes);
            output.Seek(0, SeekOrigin.Begin);
        }
        private static void FillDocument(WordprocessingDocument docx, XmlDocument xml)
        {
            // Get document.xml from the docx package
            using (Stream streamDocument = docx.MainDocumentPart.GetStream(FileMode.Open, FileAccess.ReadWrite))
            {
                // Create and load a new transform object
                XslCompiledTransform xslt = NewTransformFromResource(InfoPath2WordStyleSheet);

                // Pass wordTemplate parameter to stylesheet
                XsltArgumentList xArgs = new XsltArgumentList();
                xArgs.AddParam(&quot;wordTemplate&quot;, &quot;&quot;, XmlDocumentFromStream(streamDocument));

                // Transform infopath data to word document
                streamDocument.Seek(0, SeekOrigin.Begin);
                xslt.Transform(xml, xArgs, streamDocument);

                // Save
                docx.MainDocumentPart.Document.Save();
            }
        }
        private static XmlDocument FormatInfoPathForm(XPathNavigator infoPathForm, Stream viewStream)
        {
            using (MemoryStream strFormattedInfoPathForm = new MemoryStream())
            {
                // Create and load transform object
                XslCompiledTransform xslFormatter = NewTransformFromResource(InfoPathFormatStyleSheet, false, false, true);

                // Create transformation argument list
                XsltArgumentList xArgs = new XsltArgumentList();
                MyLib.Xslt.Formatting xo = new MyLib.Xslt.Formatting();
                xArgs.AddExtensionObject(xo.NamespaceUri, xo);
                XmlDocument xView = new XmlDocument();
                xView.Load(viewStream);
                xArgs.AddParam(&quot;view&quot;, &quot;&quot;, xView);

                // Transform InfoPath form to a form with formatted values
                xslFormatter.Transform(infoPathForm, xArgs, strFormattedInfoPathForm);

                // Output formatted form
                strFormattedInfoPathForm.Seek(0, SeekOrigin.Begin);
                XmlDocument result = new XmlDocument();
                result.Load(strFormattedInfoPathForm);
                return result;
            }
        }
        private static XmlDocument XmlDocumentFromStream(Stream inStream)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(inStream);
            return xDoc;
        }
        private static XslCompiledTransform NewTransformFromResource(string stylesheetResource)
        {
            return NewTransformFromResource(stylesheetResource, false, null, null);
        }

       
        private static XslCompiledTransform NewTransformFromResource(string stylesheetResource, bool enableDebug)
        {
            return NewTransformFromResource(stylesheetResource, enableDebug, null, null);
        }
        private static XslCompiledTransform NewTransformFromResource(string stylesheetResource, bool enableDebug, bool enableDocumentFunction, bool enableScript)
        {
            return NewTransformFromResource(stylesheetResource, enableDebug, new XsltSettings(enableDocumentFunction, enableScript), null);
        }
        private static XslCompiledTransform NewTransformFromResource(string stylesheetResource, bool enableDebug, XsltSettings settings, XmlResolver resolver)
        {
            using (Stream strStylesheet = Assembly.GetExecutingAssembly().GetManifestResourceStream(stylesheetResource))
            {
                XmlTextReader xsltReader = new XmlTextReader(strStylesheet);
                XslCompiledTransform xslt = new XslCompiledTransform(enableDebug);
                xslt.Load(xsltReader, settings, resolver);
                return xslt;
            }
        }
        private static void Load(XslCompiledTransform xsltTransform, Stream xsltStream)
        {
            // Get xslt stream reader
            XmlTextReader xsltReader = new XmlTextReader(xsltStream);
            xsltTransform.Load(xsltReader);
        }
        private static void Transform(XslCompiledTransform xsltTransform, Stream xmlInStream, Stream xmlOutStream)
        {
            // Get xml stream reader
            XmlTextReader xmlReader = new XmlTextReader(xmlInStream);

            // Create stream writer
            XmlTextWriter xmlWriter = new XmlTextWriter(xmlOutStream, Encoding.UTF8);

            // Transform to new stylesheet
            xsltTransform.Transform(xmlReader, xmlWriter);
        }
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=87&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/03/06/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-%e2%80%93-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
		<item>
		<title>Implement InfoPath formatString function for customized form data conversions</title>
		<link>http://benny56sp.wordpress.com/2010/02/17/implement-infopath-formatstring-function-for-customized-form-data-conversions/</link>
		<comments>http://benny56sp.wordpress.com/2010/02/17/implement-infopath-formatstring-function-for-customized-form-data-conversions/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 00:04:05 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[InfoPath 2007]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Xslt]]></category>
		<category><![CDATA[browser-enabled]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[extension object]]></category>
		<category><![CDATA[formatString]]></category>
		<category><![CDATA[InfoPath]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=81</guid>
		<description><![CDATA[InfoPath 2007 solutions contain at least one view to display the form in a window. Additional views may be necessary to send the form by email, to other applications or to a web browser. Views are xslt stylesheets which are packed into the InfoPath 2007 solution file (*.xsn). Remember a xsn file is a cab file. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=81&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>InfoPath 2007 solutions contain at least one view to display the form in a window. Additional views may be necessary to send the form by email, to other applications or to a web browser. Views are xslt stylesheets which are packed into the InfoPath 2007 solution file (*.xsn). Remember a xsn file is a cab file. You can access the content by simply renaming the solution file to *.cab.</p>
<p>If you create your own xslt stylesheet or if you use an existing InfoPath view to programmatically transform your form data, you normally will need to format multiline strings, numbers, date and time values. The InfoPath object model offers the method <strong>Application.FormatString</strong> which can be used for all formatting. Also the InfoPath views try to call the method <strong>formatString</strong> during transformation. Example:</p>
<p><strong><em>InfoPath view snippet</em></strong></p>
<p><pre class="brush: xml; wrap-lines: false;">
&lt;xsl:choose&gt;
    &lt;xsl:when test=&quot;function-available('xdFormatting:formatString')&quot;&gt;
        &lt;xsl:value-of select=&quot;xdFormatting:formatString(fp:address,&amp;quot;string&amp;quot;,&amp;quot;plainMultiline&amp;quot;)&quot; disable-output-escaping=&quot;yes&quot;/&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
             &lt;xsl:value-of select=&quot;fp:address&quot; disable-output-escaping=&quot;yes&quot;/&gt;
    &lt;/xsl:otherwise&gt;
&lt;/xsl:choose&gt;
</pre></p>
<p><strong>Problem</strong></p>
<p>The FormatString method is not available in browser-enabled forms. Browser-enabled forms use a different object model.</p>
<p>As you can see from the snippet above the xslt processor tries to call the <strong>formatString</strong> function which is not defined as member of the processor. It is defined as member of an xslt extension object which is passed as an input parameter.</p>
<p><strong>Task</strong></p>
<p>Write a C# class with the method <strong>formatString</strong>. The method must be compatible to <strong>FormatString </strong>method which is defined by the InfoPath object model. See <a title="Application.FormatString Method" href="http://msdn.microsoft.com/en-us/library/bb229767.aspx" target="_blank">Application.FormatString Method</a> for more information. Better said the method &#8220;should be&#8221; compatible, if you want to use stylesheets (views) which are designed with the InfoPath editor.</p>
<p><strong>Solution</strong></p>
<p>Below please find the listing <strong><em>MyLib.Xslt.Formatting</em></strong> which realized the xslt extension object. To pass the extension object to the xslt processor: </p>
<p><pre class="brush: csharp; wrap-lines: false;">
 // Create transformation argument list
 XsltArgumentList xArgs = new XsltArgumentList();
 MyLib.Xslt.Formatting xo = new MyLib.Xslt.Formatting();
 xArgs.AddExtensionObject(xo.NamespaceUri, xo);
</pre></p>
<p><strong>Conclusion</strong></p>
<p>If you programmatically tranform InfoPath form data you can use an xslt stylesheet together with an an extension object. The extension object contains the method <strong>formatString</strong> which is can also called by InfoPath designed stylesheets (views). The C# class listing <strong><em>MyLib.Xslt.Formatting</em></strong> below realizes the extension object.</p>
<p>Note: The class below does not offer full 100% of the functionality. Missing parts are commented and will be added later. Sorry, guys, you forced me to publish this article before I could finish all. Feel free to publish a completed or even better solution and let me know.</p>
<p><strong><em>MyLib.Xslt.Formatting</em></strong></p>
<p><pre class="brush: csharp; wrap-lines: false;">

using System;
using System.Collections.Specialized;
using System.Globalization;
using System.Reflection;
using System.Threading;
using System.Xml.XPath;
namespace MyLib.Xslt
{
    /// &lt;summary&gt;
    /// This class contains xslt extension methods
    /// &lt;/summary&gt;
    public class Formatting
    {
        /**************/
        /* Properties */
        /**************/

        public string NamespaceUri
        {
            get { return &quot;&lt;a href=&quot;http://schemas.microsoft.com/office/infopath/2003/xslt/formatting&quot;&gt;http://schemas.microsoft.com/office/infopath/2003/xslt/formatting&lt;/a&gt;&quot;; }
        }

        /******************/
        /* Public methods */
        /******************/

        /// &lt;summary&gt;
        /// Formats the specified string or XML node according to the specified category and options parameters.
        /// This extension method is used by browser-enable InfoPath forms
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;input&quot;&gt;The string value or XML node to be formatted.&lt;/param&gt;
        /// &lt;param name=&quot;category&quot;&gt;The string value that specifies the category used for formatting. Values include number, percentage, currency, date, time, and datetime.&lt;/param&gt;
        /// &lt;param name=&quot;options&quot;&gt;The string value that specifies the options used for formatting. Takes the form of a case-sensitive string in the format &quot;optionName:value&quot;.&lt;/param&gt;
        /// &lt;returns&gt;the formatted string&lt;/returns&gt;
        /// &lt;see cref=&quot;http://msdn.microsoft.com/en-us/library/bb229767.aspx&quot;/&gt;
        public string formatString(object input, string category, string options)
        {
            // Get expected type of MS.Internal.Xml.XPath.XPathArrayIterator
            Type t = input.GetType();

            // Move to first node and examine its value
            if ((bool)t.InvokeMember(&quot;MoveNext&quot;, BindingFlags.InvokeMethod, null, input, null))
            {
                XPathNavigator xNav = (XPathNavigator)t.InvokeMember(&quot;Current&quot;, BindingFlags.GetProperty, null, input, null);
                string val = xNav.Value;
                NameValueCollection nvcOptions = getOptions(options);
                switch (category)
                {
                    case &quot;number&quot;:
                        return fmtNumber(val, nvcOptions);
                    case &quot;percentage&quot;:
                        return fmtPercentage(val, nvcOptions);
                    case &quot;currency&quot;:
                        return fmtCurrency(val, nvcOptions);
                    case &quot;date&quot;:
                        return fmtDate(val, nvcOptions);
                    case &quot;time&quot;:
                        return fmtTime(val, nvcOptions);
                    case &quot;datetime&quot;:
                        return fmtDateTime(val, nvcOptions);
                    case &quot;string&quot;:
                        return fmtString(val, nvcOptions);
                    default:
                        throw new NotImplementedException();
                }
            }
            else return string.Empty;
        }

        /*******************/
        /* Private methods */
        /*******************/

        /// &lt;summary&gt;
        /// Format a numerical value.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;value&quot;&gt;Value to be formatted&lt;/param&gt;
        /// &lt;param name=&quot;options&quot;&gt;Valid options include locale, numDigits, leadingZero, grouping, decimalSep, thousandSep, and negativeOrder&lt;/param&gt;
        /// &lt;returns&gt;the formatted value&lt;/returns&gt;
        private string fmtNumber(string value, NameValueCollection options)
        {
            // Set culture
            string option = options[&quot;locale&quot;];
            CultureInfo culture = (option == null) ? Thread.CurrentThread.CurrentUICulture : CultureInfo.GetCultureInfo(int.Parse(option));

            // Get number format provider
            NumberFormatInfo nfi = culture.NumberFormat.Clone() as NumberFormatInfo;

            // Set number of decimal digits
            option = options[&quot;numDigits&quot;];
            if (option != null) nfi.NumberDecimalDigits = int.Parse(option);

            //// Specifies whether to use leading zeros in decimal fields.
            //// Specify 0 to indicate no leading zeros and 1 to indicate leading zeros.
            //// Defaults to the corresponding value in regional settings if not specified.
            //int leadingZero = 0;

            // Specifies the size of each group of digits to the left of the decimal.
            // Values in the range 0–9 and value 32 are valid. Value 32 indicates that the grouping is three digits, then two digits thereafter.
            // Defaults to the corresponding value in regional settings if not specified.
            option = options[&quot;grouping&quot;];
            if (option != null)
            {
                int groupSize = int.Parse(option);
                if (groupSize &lt; 10) nfi.NumberGroupSizes = new int[] {groupSize};
                else nfi.NumberGroupSizes = new int[] {3, 2};
            }

            // Set the decimal separator string
            option = options[&quot;decimalSep&quot;];
            if (option != null) nfi.NumberDecimalSeparator = option;

            // Set the thousands separator string.
            option = options[&quot;thousandSep&quot;];
            if (option != null) nfi.NumberGroupSeparator = option;

            //// Specifies the negative number mode. Defaults to the corresponding value in regional settings if not specified.
            //int negativeOrder = 1;

            return string.Format(nfi, &quot;{0:N}&quot;, double.Parse(value, new CultureInfo(&quot;en-US&quot;)));
        }
        /// &lt;summary&gt;
        /// Format percentage value.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;val&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;nvcOptions&quot;&gt;Valid options for this category include locale, numDigits, leadingZero, grouping, decimalSep, thousandSep, and negativeOrder.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private string fmtPercentage(string value, NameValueCollection options)
        {
            // Set culture
            string option = options[&quot;locale&quot;];
            CultureInfo culture = (option == null) ? Thread.CurrentThread.CurrentUICulture : CultureInfo.GetCultureInfo(int.Parse(option));

            // Get number format provider
            NumberFormatInfo nfi = culture.NumberFormat.Clone() as NumberFormatInfo;

            // Set number of decimal digits
            option = options[&quot;numDigits&quot;];
            if (option != null) nfi.PercentDecimalDigits = int.Parse(option);

            //// Specifies whether to use leading zeros in decimal fields.
            //// Specify 0 to indicate no leading zeros and 1 to indicate leading zeros.
            //// Defaults to the corresponding value in regional settings if not specified.
            //int leadingZero = 0;

            // Specifies the size of each group of digits to the left of the decimal.
            // Values in the range 0–9 and value 32 are valid. Value 32 indicates that the grouping is three digits, then two digits thereafter.
            // Defaults to the corresponding value in regional settings if not specified.
            option = options[&quot;grouping&quot;];
            if (option != null)
            {
                int groupSize = int.Parse(option);
                if (groupSize &lt; 10) nfi.PercentGroupSizes = new int[] { groupSize };
                else nfi.NumberGroupSizes = new int[] { 3, 2 };
            }

            // Set the decimal separator string
            option = options[&quot;decimalSep&quot;];
            if (option != null) nfi.PercentDecimalSeparator = option;

            // Set the thousands separator string.
            option = options[&quot;thousandSep&quot;];
            if (option != null) nfi.PercentGroupSeparator = option;

            //// Specifies the negative number mode. Defaults to the corresponding value in regional settings if not specified.
            //int negativeOrder = 1;

            return string.Format(nfi, &quot;{0:P}&quot;, double.Parse(value, new CultureInfo(&quot;en-US&quot;)));
        }
        /// &lt;summary&gt;
        /// Format currency value
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;val&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;nvcOptions&quot;&gt;Valid options for this category include locale, numDigits, leadingZero, grouping, decimalSep, thousandSep, negativeOrder, positiveOrder, and currencyLocale.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private string fmtCurrency(string value, NameValueCollection options)
        {
            throw new NotImplementedException();
        }
        /// &lt;summary&gt;
        ///
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;val&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;nvcOptions&quot;&gt;Valid options for this category include locale, dateFormat, useAltCalendar, and useEnglishStringsAlways.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private string fmtDate(string value, NameValueCollection options)
        {
            // Set culture
            string option = options[&quot;locale&quot;];
            CultureInfo culture = (option == null) ? Thread.CurrentThread.CurrentUICulture : CultureInfo.GetCultureInfo(int.Parse(option));

            // Get date time format provider
            DateTimeFormatInfo dtfi = culture.DateTimeFormat.Clone() as DateTimeFormatInfo;
            string baseFormat = &quot;{{0:{0}}}&quot;;

            // dateFormat: Specifies a format picture string that is used to form the date string.
            // The values Short Date, Long Date, Year Month, and none may also be used to indicate
            // short date format, long date format, year month format, and no format, respectively.
            // Short Date, Long Date, and Year Month are the default formats provided by the
            // operating system's regional and language settings.
            string fmt = &quot;{0}&quot;;
            switch (options[&quot;dateFormat&quot;])
            {
                case &quot;Short Date&quot;:
                    fmt = string.Format(baseFormat, dtfi.ShortDatePattern);
                    break;

                case &quot;Long Date&quot;:
                    fmt = string.Format(baseFormat, dtfi.LongDatePattern);
                    break;

                case &quot;Year Month&quot;:
                    fmt = string.Format(baseFormat, dtfi.YearMonthPattern);
                    break;

                case &quot;none&quot;:
                    fmt = &quot;{0}&quot;;
                    break;

                default:
                    fmt = string.Format(baseFormat, dtfi.ShortDatePattern);
                    break;
            }

            // useAltCalendar: Specifies whether to use an alternate calendar for date formatting.
            // Specify 0 to use the normal calendar and 1 to use the alternate calendar.
            // Defaults to 0 if not specified.

            // useEnglishStringsAlways: Specifies whether to always use English strings for date formatting.
            // Specify 0 to use the language specified by locale and 1 to always use English.
            // Defaults to 0 if not specified.

            // Output result
            return string.Format(dtfi, fmt, DateTime.Parse(value));
        }
        /// &lt;summary&gt;
        /// Format time values.
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;value&quot;&gt;Value to be formatted&lt;/param&gt;
        /// &lt;param name=&quot;options&quot;&gt;Valid options for this category include locale, timeFormat, and noSeconds.&lt;/param&gt;
        /// &lt;returns&gt;the formatted value&lt;/returns&gt;
        private string fmtTime(string value, NameValueCollection options)
        {
            // Set culture
            string option = options[&quot;locale&quot;];
            CultureInfo culture = (option == null) ? Thread.CurrentThread.CurrentUICulture : CultureInfo.GetCultureInfo(int.Parse(option));

            // Get date time format provider
            DateTimeFormatInfo dtfi = culture.DateTimeFormat.Clone() as DateTimeFormatInfo;
            string baseFormat = &quot;{{0:{0}}}&quot;;

            // noSeconds: Specifies whether to not use seconds.
            // Specify 0 to use seconds and 1 to not use seconds. Defaults to 0 if not specified.
            option = options[&quot;noSeconds&quot;];
            string fmt = string.Format(baseFormat, dtfi.LongTimePattern);
            if (option != null &amp;&amp; int.Parse(option) == 1) fmt = string.Format(baseFormat, dtfi.ShortTimePattern);

            // timeFormat: Specifies a format string that is used to form the time string.
            // The value none may also be used to indicate no format.
            // Defaults to the time format in regional settings if not specified.
            option = options[&quot;timeFormat&quot;];
            if (option != null) fmt = string.Format(baseFormat, option);

            // Output result
            return string.Format(dtfi, fmt, DateTime.Parse(value));
        }
        /// &lt;summary&gt;
        /// Format DateTime values
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;value&quot;&gt;Value to be formatted&lt;/param&gt;
        /// &lt;param name=&quot;nvcOptions&quot;&gt;Valid options for this category include locale, dateFormat, timeFormat, noSeconds, useAltCalendar, and useEnglishStringAlways.&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private string fmtDateTime(string val, NameValueCollection nvcOptions)
        {
            throw new NotImplementedException();
        }
        /// &lt;summary&gt;
        /// Formats a string
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;value&quot;&gt;Value to be formatted&lt;/param&gt;
        /// &lt;param name=&quot;options&quot;&gt;Valid options for this category include plainMultiline&lt;/param&gt;
        /// &lt;returns&gt;the formatted string&lt;/returns&gt;
        private string fmtString(string value, NameValueCollection options)
        {
            string option = options[&quot;plainMultiline&quot;];
            if (option != null)
            {
                return (value == string.Empty) ? &quot;&lt;br/&gt;&quot; : value.Replace(&quot;\r\n&quot;,&quot;&lt;br/&gt;&quot;);
            }

            return value;
        }
        /// &lt;summary&gt;
        /// Returns the format options as a name value collection
        /// &lt;/summary&gt;
        private NameValueCollection getOptions(string options)
        {
            NameValueCollection nvc = new NameValueCollection();
            string[] nameValues = options.Split(new char[] { ':', ';' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i &lt; nameValues.Length; i++)
            {
                string name = nameValues[i++];
                string val = (i &lt; nameValues.Length) ? nameValues[i] : string.Empty;
                nvc.Add(name, val);
            }
            return nvc;
        }

    }
}
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/81/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/81/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/81/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=81&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/02/17/implement-infopath-formatstring-function-for-customized-form-data-conversions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
		<item>
		<title>How to transform InfoPath 2007 form data into a Word 2007 document &#8211; Part 2</title>
		<link>http://benny56sp.wordpress.com/2010/02/13/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-part-2/</link>
		<comments>http://benny56sp.wordpress.com/2010/02/13/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-part-2/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 21:27:55 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[InfoPath 2007]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Word 2007]]></category>
		<category><![CDATA[Xslt]]></category>
		<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[Transformation]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=72</guid>
		<description><![CDATA[Please review Part 1 to get an overview on how to convert InfoPath 2007 form data into a Word 2007 document using a Word 2007 template. You also will find  the listing of InfoPath2Word.xslt stylesheet which does the final transformation for individual fields and repeated tables. Continuing with the second step If your InfoPath form contains not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=72&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Please review <a title="Part 1" href="http://wp.me/pNM5S-M" target="_blank">Part 1</a> to get an overview on how to convert InfoPath 2007 form data into a Word 2007 document using a Word 2007 template. You also will find  the listing of <strong><em>InfoPath2Word.xslt</em></strong> stylesheet which does the final transformation for individual fields and repeated tables.</p>
<p><strong>Continuing with the second step</strong></p>
<p>If your InfoPath form contains not only simple text but also formatted numbers, date and time values it is necessary to preformat the raw data. InfoPath stores for example a date in this way &#8220;2010-02-13&#8243; instead of &#8220;02/13/2010&#8243; or &#8220;13.2.2010&#8243; or any other culture dependent date format. Similarly numbers, currencies or percentage values are stored as integer or real values without any formatting.</p>
<p>When you design a InfoPath view you also define all formatting information by setting the properties of all data fields. Because the format information is already stored in a view, it is natural to use this by further processes again.</p>
<p>Remember an InfoPath solution file (*.xsn) is a file cabinet. Simply rename the solution file to *.cab to access all the files inside the cabinet. The InfoPath views are xslt stylesheets with default filenames of view1.xsl, view2.xsl and so on. These stylesheets present the form data to the user in that way you have designed it using the InfoPath designer.</p>
<p><strong>Task</strong></p>
<p>Create an xslt stylesheet to transform InfoPath form data to itself. Keep the structure but format the data. Use an InfoPath view as an input parameter to get all format information of the individual fields and repeated elements.</p>
<p><strong>Solution</strong></p>
<p>Below please find the listing of the stylesheet <strong><em>InfoPathFormat.xslt</em></strong> which fullfills the task. The stylesheet calls the function <em>formatString()</em>, which is defined by an transform extension object. The extension object is written in C#  and will be posted next.</p>
<p><strong>Conclusion</strong></p>
<p>The stylesheet <strong><em>InfoPathFormat.xslt</em></strong> formats InfoPath form data by using a view file as input parameter. The resulting xml file together with a Word 2007 template will be used by <strong><em>InfoPath2Word.xslt</em></strong>, which is presented in <a title="Part 1" href="http://wp.me/pNM5S-M" target="_blank">Part 1</a> of this blog, to perform the final transformation to Word 2007.</p>
<p><strong><em>InfoPathFormat.xslt</em></strong></p>
<p><pre class="brush: xml; auto-links: false; wrap-lines: false;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;!--
This stylesheet is used to format InfoPath form data, whereby the formatting
information is taken from a view stylesheet, typically from view1.xsl of the
InfoPath cabinet.
--&gt;
&lt;xsl:stylesheet
  version=&quot;1.0&quot;
  xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
  xmlns:xd=&quot;http://schemas.microsoft.com/office/infopath/2003&quot;
  xmlns:xdFormatting=&quot;http://schemas.microsoft.com/office/infopath/2003/xslt/formatting&quot;
  xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot;
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xmlns:scrpt=&quot;http://tempuri.org/InfoPath/Scripts&quot;
  exclude-result-prefixes=&quot;msxsl&quot;
&gt;
  &lt;!-- ======= --&gt;
  &lt;!-- Setting --&gt;
  &lt;!-- ======= --&gt;

  &lt;xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot; /&gt;

  &lt;!-- ========== --&gt;
  &lt;!-- Parameters --&gt;
  &lt;!-- ========== --&gt;

  &lt;!--
  The input parameters are preset for debugging purpose. For runtime
  use only one parameter either viewLocation or view.
  --&gt;

  &lt;xsl:param name=&quot;viewLocation&quot; select=&quot;'Sample/view1.xsl'&quot; /&gt;
  &lt;xsl:param name=&quot;view&quot; select=&quot;document($viewLocation)&quot; /&gt;

  &lt;!-- ========= --&gt;
  &lt;!-- Variables --&gt;
  &lt;!-- ========= --&gt;

  &lt;!-- Contains a list of data bindings --&gt;
  &lt;xsl:variable name=&quot;bindings&quot; select=&quot;$view//*[@xd:binding]&quot; /&gt;

  &lt;!-- ======= --&gt;
  &lt;!-- Scripts --&gt;
  &lt;!-- ======= --&gt;
 
  &lt;!-- Embedded script to implement the ends-with function --&gt;
  &lt;msxsl:script language =&quot;JScript&quot; implements-prefix=&quot;scrpt&quot;&gt;
    function EndsWith(str, iterator) {
    var s1 = str.Value;
    iterator.MoveNext();
    var s2 = iterator.Current.Value
    return s1.EndsWith(s2);
    }
  &lt;/msxsl:script&gt;

  &lt;!-- ==== --&gt;
  &lt;!-- Root --&gt;
  &lt;!-- ==== --&gt;
 
  &lt;!-- Entry point --&gt;
  &lt;xsl:template match=&quot;/&quot;&gt;
    &lt;xsl:copy-of select=&quot;processing-instruction()&quot; /&gt;
    &lt;xsl:apply-templates select=&quot;*&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Nested elements --&gt;
  &lt;xsl:template match=&quot;*[*]&quot;&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:apply-templates select=&quot;@* | *&quot; /&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Final elements --&gt;
  &lt;xsl:template match=&quot;*&quot;&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:apply-templates select=&quot;@* | text()&quot; /&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Attributes --&gt;
  &lt;xsl:template match=&quot;@*&quot;&gt;
    &lt;xsl:variable name=&quot;_binding&quot;&gt;
      &lt;xsl:apply-templates select=&quot;.&quot; mode=&quot;get-binding&quot; /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:variable name=&quot;binding&quot; select=&quot;msxsl:node-set($_binding)&quot; /&gt;
    &lt;xsl:attribute name=&quot;{name()}&quot;&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test=&quot;$binding&quot;&gt;
          &lt;xsl:apply-templates select=&quot;$binding/*&quot;&gt;
            &lt;xsl:with-param name=&quot;value&quot; select=&quot;.&quot; /&gt;
          &lt;/xsl:apply-templates&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:value-of select=&quot;.&quot; /&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:attribute&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Text nodes --&gt;
  &lt;xsl:template match=&quot;text()&quot;&gt;
    &lt;xsl:variable name=&quot;_binding&quot;&gt;
      &lt;xsl:apply-templates select=&quot;.&quot; mode=&quot;get-binding&quot; /&gt;
    &lt;/xsl:variable&gt;
    &lt;xsl:variable name=&quot;binding&quot; select=&quot;msxsl:node-set($_binding)&quot; /&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;$binding&quot;&gt;
        &lt;xsl:apply-templates select=&quot;$binding/*&quot;&gt;
          &lt;xsl:with-param name=&quot;value&quot; select=&quot;.&quot; /&gt;
        &lt;/xsl:apply-templates&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:copy /&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;

  &lt;!-- FileAttachment output --&gt;
  &lt;xsl:template match=&quot;span[@xd:xctname='FileAttachment']&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:value-of select=&quot;$value&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Date and time output --&gt;
  &lt;xsl:template match=&quot;span[@xd:xctname='PlainText' or @xd:xctname='DTPicker_DTText'][@xd:datafmt]&quot; priority=&quot;2&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:apply-templates select=&quot;@xd:datafmt&quot;&gt;
      &lt;xsl:with-param name=&quot;value&quot; select=&quot;$value&quot; /&gt;
    &lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Plaintext output --&gt;
  &lt;xsl:template match=&quot;span[@xd:xctname='PlainText']&quot; priority=&quot;1&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:value-of select=&quot;$value&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Checkbox output --&gt;
  &lt;xsl:template match=&quot;input[@xd:xctname='CheckBox']&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;$value=@xd:onValue&quot;&gt;
        &lt;!-- Wingding 2 crossed square --&gt;
        &lt;xsl:text&gt;&#84;&lt;/xsl:text&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;!-- Windging 2 square --&gt;
        &lt;xsl:text&gt;&#163;&lt;/xsl:text&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;

  &lt;!-- =========== --&gt;
  &lt;!-- @xd:datafmt --&gt;
  &lt;!-- =========== --&gt;
 
  &lt;!-- Formatted multiline output --&gt;
  &lt;xsl:template match=&quot;@xd:datafmt[.='&amp;quot;string&amp;quot;,&amp;quot;plainMultiline&amp;quot;'][function-available('xdFormatting:formatString')]&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:variable name=&quot;type&quot; select=&quot;substring-before(substring-after(., '&amp;quot;'), '&amp;quot;,&amp;quot;')&quot; /&gt;
    &lt;xsl:variable name=&quot;options&quot; select=&quot;substring-before(substring-after(., '&amp;quot;,&amp;quot;'), '&amp;quot;')&quot; /&gt;
    &lt;xsl:value-of select=&quot;xdFormatting:formatString($value, $type, $options)&quot; disable-output-escaping=&quot;yes&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Standard multiline output --&gt;
  &lt;xsl:template match=&quot;@xd:datafmt[.='&amp;quot;string&amp;quot;,&amp;quot;plainMultiline&amp;quot;']&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:value-of select=&quot;$value&quot; disable-output-escaping=&quot;yes&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Formatted output of number, percentage, currency, date and time values --&gt;
  &lt;xsl:template match=&quot;@xd:datafmt[function-available('xdFormatting:formatString')]&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:variable name=&quot;type&quot; select=&quot;substring-before(substring-after(., '&amp;quot;'), '&amp;quot;,&amp;quot;')&quot; /&gt;
    &lt;xsl:variable name=&quot;options&quot; select=&quot;substring-before(substring-after(., '&amp;quot;,&amp;quot;'), '&amp;quot;')&quot; /&gt;
    &lt;xsl:value-of select=&quot;xdFormatting:formatString($value, $type, $options)&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- Standard output --&gt;
  &lt;xsl:template match=&quot;@xd:datafmt&quot;&gt;
    &lt;xsl:param name=&quot;value&quot; /&gt;
    &lt;xsl:value-of select=&quot;$value&quot; /&gt;
  &lt;/xsl:template&gt;

  &lt;!-- =========== --&gt;
  &lt;!-- get-binding --&gt;
  &lt;!-- =========== --&gt;
 
  &lt;xsl:template match=&quot;@*&quot; mode=&quot;get-binding&quot;&gt;
    &lt;!-- Get absolute xpath expression of the current attribute --&gt;
    &lt;xsl:variable name=&quot;xpath&quot;&gt;
      &lt;xsl:apply-templates select=&quot;parent::*&quot; mode=&quot;get-binding&quot; /&gt;
      &lt;xsl:text&gt;/@&lt;/xsl:text&gt;
      &lt;xsl:value-of select=&quot;name()&quot; /&gt;
    &lt;/xsl:variable&gt;
    &lt;!-- @xd:binding contains a relative xpath. $xpath contains the absolute path. --&gt;
    &lt;!-- Filter the first binding where the absolute path $xpath ends with the relative path @xd:binding. --&gt;
    &lt;xsl:copy-of select=&quot;$bindings[scrpt:EndsWith($xpath, @xd:binding)][1]&quot;/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match=&quot;text()&quot; mode=&quot;get-binding&quot;&gt;
    &lt;!-- Get absolute xpath expression of the current element --&gt;
    &lt;xsl:variable name=&quot;xpath&quot;&gt;
      &lt;xsl:apply-templates select=&quot;parent::*&quot; mode=&quot;get-binding&quot; /&gt;
    &lt;/xsl:variable&gt;
    &lt;!-- @xd:binding contains a relative xpath. $xpath contains the absolute path. --&gt;
    &lt;!-- Filter the first binding where the absolute path $xpath ends with the relative path @xd:binding. --&gt;
    &lt;xsl:copy-of select=&quot;$bindings[scrpt:EndsWith($xpath, @xd:binding)][1]&quot;/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match=&quot;*&quot; mode=&quot;get-binding&quot;&gt;
    &lt;!-- Output parent xpath terms first --&gt;
    &lt;xsl:apply-templates select=&quot;parent::*&quot; mode=&quot;get-binding&quot; /&gt;
    &lt;!-- Output the current term of the xpath expression --&gt;
    &lt;xsl:text&gt;/&lt;/xsl:text&gt;
    &lt;xsl:value-of select=&quot;name()&quot; /&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=72&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/02/13/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
		<item>
		<title>How to transform InfoPath 2007 form data into a Word 2007 document &#8211; Part 1</title>
		<link>http://benny56sp.wordpress.com/2010/02/12/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-part-1/</link>
		<comments>http://benny56sp.wordpress.com/2010/02/12/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-part-1/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 03:43:51 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[InfoPath 2007]]></category>
		<category><![CDATA[Word 2007]]></category>
		<category><![CDATA[Xslt]]></category>
		<category><![CDATA[Conversion]]></category>
		<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[OpenXml]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Transformation]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=48</guid>
		<description><![CDATA[InfoPath is designed for easy handling of electronical forms. Used in conjunction with SharePoint you have a powerful tool to quickly collect complex data. Although electronical forms are most suitable for collaboration of team members there is still an interface lack. Today you still can not do without paper forms and documents. To secure a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=48&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>InfoPath is designed for easy handling of electronical forms. Used in conjunction with SharePoint you have a powerful tool to quickly collect complex data. Although electronical forms are most suitable for collaboration of team members there is still an interface lack. Today you still can not do without paper forms and documents. To secure a contract or agreement, legally, you need the personal signature of the parties.</p>
<p>Which is your workaround? In case you need for example a contract with your customer you would probably design a electronical form to collect the customer&#8217;s data and contract details and another form or document which contains the contract text and some space for manual signatures. Also very often you will transfer the data from the electronical form to your paper document manually.</p>
<p><strong>Task</strong></p>
<p>You need a tool which automatically transforms a InfoPath 2007 form into a Word 2007 document.</p>
<p><strong>Possible Solutions</strong></p>
<ol>
<li>With InfoPath you can design a print view and send it to your printer. The disadvantage is that you will get a html output with all the difficulties of formatting, specially when your field sizes and text sizes are of variable lengths.</li>
<li>InfoPath 2003 SDK includes the &#8220;InfoPath to Word Wizard&#8221;. You can still use this tool for InfoPath 2007. The wizard helps to create a xsl stylesheet which can be uploaded to InfoPath as a print view for Word. When you print your form it is first transformed to Word and then output. The disadvantage: The transformation is still to html output only shown by Word. Again you need manual formatting for a final result.</li>
<li>Word 2007 implements the OpenXml standards which means you easily can create a document programmatically. Downloading the OpenXml SDK 2.0 gives you all the tools and libraries necessary. Disadvantage: Well, if you have not only one form to convert but many or if you have changing forms there are a lot of programming works and updates administration.</li>
<li>You may follow this block to see how you can merge InfoPath 2007 form data (.xml) and a Word 2007 template (.dotx) to a resulting Word 2007 document (.docx). Furthermore the final document will be attached to the InfoPath form itself to have both forms available the same time on your SharePoint. If you need to print and sign the document simply download it, print it, sign it, scan it and upload the signed version as a .pdf file to the InfoPath form again. A piece of C# code assures that your signed document is not lost.</li>
</ol>
<p><strong>Solution #4: Here we go</strong></p>
<p>There are some milestones to achieve until you will have the final solution. The result will be a little C# class library with embedded resources which will be used by InfoPath. We need:</p>
<ol>
<li>an xslt stylesheet to transform InfoPath 2007 form data into an OpenXml compatible xml file which can be loaded into a Word 2007 package. Remember Word 2007 is actually a zip archive. Rename a document to *.zip and discover what is inside.</li>
<li>an additional stylesheet to preformat the form data. This is necessary to provide number, percentage, date and time formatting prior to the Word transformation.</li>
<li>a little piece of C# which reads the Word template, examines the InfoPath solution for formatting purpose, retrieves the form data, creates the Word document and saves the result as an InfoPath file attachement.</li>
</ol>
<p><strong>Beginning with the first step</strong></p>
<p>Below please find the xslt stylesheet which transforms InfoPath form data to Word document based on a Word template which is passed as a parameter. To test the stylesheet:</p>
<ol>
<li>Create an InfoPath 2007 form</li>
<li>Fill the form with sample data and save it</li>
<li>Create a Word 2007 template (*.dotx)</li>
<li>Attach the form&#8217;s schema to the Word template
<ol>
<li>Open the word template</li>
<li>Select the <strong>developer tab</strong> (Maybe you need to enable it first)</li>
<li>In the Xml section, select <strong>Schema</strong></li>
<li>Click <strong>Add Schema</strong> button</li>
<li>Navigate to the sample form and select it. Click to the <strong>Open</strong> button</li>
<li>Click <strong>OK</strong> to close Schema settings and <strong>OK</strong> to close the <strong>Templates and Add-ins</strong> windows</li>
<li>Select <strong>Structure</strong> from the <strong>XML</strong> section in the ribbon to view the available elements that are defined by the schema.</li>
</ol>
</li>
<li>Insert all data elements you need into your Word template.</li>
<li>Finish and save your Word template</li>
<li>Now rename template from *.dotx to *.dotx.zip</li>
<li>Copy the file word/document.xml from the zip archive. -&gt; You got the input parameter for the stylesheet</li>
<li>Rename your template back to *.dotx</li>
<li>Launch Visual Studio 2005 or 2008</li>
<li>Load the InfoPath form data, the template document.xml and the stylesheet (see code below)</li>
<li>Use the stylesheet debugger to examine and debug it.</li>
</ol>
<p>When transforming InfoPath to Word a resulting xml file is generated. You may use it to replace the orginal document.xml manually within the Word package (as shown above, steps 7-9).</p>
<p>The following posts will show how to do it programmatically.</p>
<p><strong>Conclusion</strong></p>
<p>The stylesheet InfoPath2Word.xslt listed below is used to convert InfoPath 2007 form data to Word 2007. A Word 2007 template is used as input parameter for the stylesheet. Both InfoPath and Word must be based on the same xml schema to successfully merge data and template to a new document.</p>
<p><strong><em>InfoPath2Word.xslt</em></strong></p>
<p><code><pre class="brush: xml; auto-links: false; wrap-lines: false;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;!--
This stylesheet merges InfoPath 2007 form data with the appropriate
document.xml file of a Word 2007 document (docx) or template (dotx)
package.
The word document must have the same structure as the InfoPath
form data, which means that a data schema has to be added to the
Word document and data elements defined by the schema are
inserted into the document. You can achieve this by using the
developer tools of word. Inserting elements creates w:customXml
tags within the document which are used to synchronize with the
form data.
--&gt;
&lt;xsl:stylesheet
  version=&quot;1.0&quot;
  xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
  xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot;
  xmlns:w=&quot;http://schemas.openxmlformats.org/wordprocessingml/2006/main&quot;
  exclude-result-prefixes=&quot;msxsl&quot;
&gt;
  &lt;!-- ======== --&gt;
  &lt;!-- Settings --&gt;
  &lt;!-- ======== --&gt;
  &lt;xsl:output method=&quot;xml&quot; indent=&quot;yes&quot; encoding=&quot;utf-8&quot; standalone=&quot;yes&quot; /&gt;
  &lt;!-- ========== --&gt;
  &lt;!-- Parameters --&gt;
  &lt;!-- ========== --&gt;
  &lt;!--
  The input parameters are preset for debugging purpose. For runtime
  use only one parameter either wordTemplateLocation or wordTemplate
  --&gt;
  &lt;xsl:param name=&quot;wordTemplateLocation&quot; select=&quot;'Sample/document.xml'&quot; /&gt;
  &lt;xsl:param name=&quot;wordTemplate&quot; select=&quot;document($wordTemplateLocation)&quot; /&gt;
  &lt;!-- ==== --&gt;
  &lt;!-- Root --&gt;
  &lt;!-- ==== --&gt;
  &lt;!-- Passed InfoPath form data processing starts here --&gt;
  &lt;xsl:template match=&quot;/&quot;&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test=&quot;$wordTemplate&quot;&gt;
        &lt;xsl:apply-templates select=&quot;$wordTemplate/*&quot; mode=&quot;copy&quot;&gt;
          &lt;xsl:with-param name=&quot;data&quot; select=&quot;.&quot; /&gt;
        &lt;/xsl:apply-templates&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:message terminate=&quot;yes&quot;&gt;Parameter &quot;wordTemplate&quot; not passed&lt;/xsl:message&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  &lt;!-- ==== --&gt;
  &lt;!-- copy --&gt;
  &lt;!-- ==== --&gt;
  &lt;!-- General word elements output --&gt;
  &lt;xsl:template match=&quot;*&quot; mode=&quot;copy&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:copy-of select=&quot;@*&quot; /&gt;
      &lt;xsl:apply-templates select=&quot;*&quot; mode=&quot;copy&quot;&gt;
        &lt;xsl:with-param name=&quot;data&quot; select=&quot;$data&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Document text output --&gt;
  &lt;xsl:template match=&quot;w:t&quot; mode=&quot;copy&quot;&gt;
    &lt;xsl:copy-of select=&quot;.&quot; /&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Repeated data elements output --&gt;
  &lt;xsl:template match=&quot;w:tr[w:customXml[w:tc]]&quot; mode=&quot;copy&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:variable name=&quot;children&quot; select=&quot;*&quot; /&gt;
    &lt;xsl:variable name=&quot;attrs&quot; select=&quot;@*&quot; /&gt;
    &lt;xsl:for-each select=&quot;$data&quot;&gt;
      &lt;w:tr&gt;
        &lt;xsl:copy-of select=&quot;$attrs&quot; /&gt;
        &lt;xsl:apply-templates select=&quot;$children&quot; mode=&quot;copy&quot;&gt;
          &lt;xsl:with-param name=&quot;data&quot; select=&quot;.&quot; /&gt;
        &lt;/xsl:apply-templates&gt;
      &lt;/w:tr&gt;
    &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Simple empty customXml --&gt;
  &lt;xsl:template match=&quot;w:customXml[count(*)=0]&quot; mode=&quot;copy&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:variable name=&quot;element&quot; select=&quot;@w:element&quot; /&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:copy-of select=&quot;@*&quot; /&gt;
      &lt;!--Inserting form data is done here --&gt;
      &lt;xsl:apply-templates select=&quot;$data/*[local-name()=$element]/text()&quot; mode=&quot;data&quot;&gt;
        &lt;xsl:with-param name=&quot;word&quot; select=&quot;.&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Basic customXml with some formatting, typically w:tc or w:p elements--&gt;
  &lt;xsl:template match=&quot;w:customXml[count(*)=1]&quot; mode=&quot;copy&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:variable name=&quot;element&quot; select=&quot;@w:element&quot; /&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:copy-of select=&quot;@*&quot; /&gt;
      &lt;xsl:apply-templates select=&quot;*&quot; mode=&quot;insert&quot;&gt;
        &lt;xsl:with-param name=&quot;data&quot; select=&quot;$data/*[local-name()=$element]&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Nested, but not repeated customXml --&gt;
  &lt;xsl:template match=&quot;w:customXml[.//w:customXml]&quot; mode=&quot;copy&quot; priority=&quot;1&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:variable name=&quot;element&quot; select=&quot;@w:element&quot; /&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:copy-of select=&quot;@*&quot; /&gt;
      &lt;xsl:apply-templates select=&quot;*&quot; mode=&quot;copy&quot;&gt;
        &lt;xsl:with-param name=&quot;data&quot; select=&quot;$data/*[local-name()=$element]&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;!-- ====== --&gt;
  &lt;!-- insert --&gt;
  &lt;!-- ====== --&gt;
  &lt;xsl:template match=&quot;*&quot; mode=&quot;insert&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:copy-of select=&quot;@*&quot; /&gt;
      &lt;xsl:apply-templates select=&quot;*&quot; mode=&quot;insert&quot;&gt;
        &lt;xsl:with-param name=&quot;data&quot; select=&quot;$data&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;xsl:template match=&quot;w:p[not(w:r)]&quot; mode=&quot;insert&quot;&gt;
    &lt;xsl:param name=&quot;data&quot; /&gt;
    &lt;xsl:copy&gt;
      &lt;xsl:copy-of select=&quot;@*&quot; /&gt;
      &lt;xsl:apply-templates select=&quot;*&quot; mode=&quot;insert&quot;&gt;
        &lt;xsl:with-param name=&quot;data&quot; select=&quot;$data&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
      &lt;!-- Insert form data into paragraph element w:p --&gt;
      &lt;xsl:apply-templates select=&quot;$data/text()&quot; mode=&quot;data&quot;&gt;
        &lt;xsl:with-param name=&quot;word&quot; select=&quot;.&quot; /&gt;
      &lt;/xsl:apply-templates&gt;
    &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  &lt;!-- ==== --&gt;
  &lt;!-- data --&gt;
  &lt;!-- ==== --&gt;
  &lt;!-- Multiline form data --&gt;
  &lt;xsl:template match=&quot;text()[contains(., '&amp;amp;#10;')]&quot; mode=&quot;data&quot;&gt;
    &lt;xsl:param name=&quot;word&quot; /&gt;
    &lt;xsl:apply-templates select=&quot;msxsl:node-set(substring-before(., '&amp;amp;#10;'))/text()&quot; mode=&quot;data&quot;&gt;
      &lt;xsl:with-param name=&quot;word&quot; select=&quot;$word&quot; /&gt;
    &lt;/xsl:apply-templates&gt;
    &lt;xsl:apply-templates select=&quot;msxsl:node-set(substring-after(., '&amp;amp;#10;'))/text()&quot; mode=&quot;data&quot;&gt;
      &lt;xsl:with-param name=&quot;word&quot; select=&quot;$word&quot; /&gt;
      &lt;xsl:with-param name=&quot;break&quot; select=&quot;true()&quot; /&gt;
    &lt;/xsl:apply-templates&gt;
  &lt;/xsl:template&gt;
  &lt;!-- Single line form data --&gt;
  &lt;xsl:template match=&quot;text()&quot; mode=&quot;data&quot;&gt;
    &lt;xsl:param name=&quot;word&quot; /&gt;
    &lt;xsl:param name=&quot;break&quot; select=&quot;false()&quot; /&gt;
    &lt;w:r w:rsidRPr=&quot;{$word/ancestor::w:p/@w:rsidRPr}&quot;&gt;
      &lt;xsl:copy-of select=&quot;$word/ancestor::w:p/w:pPr/w:rPr&quot;/&gt;
      &lt;xsl:if test=&quot;$break&quot;&gt;
        &lt;w:br /&gt;
      &lt;/xsl:if&gt;
      &lt;w:t&gt;
        &lt;xsl:value-of select=&quot;.&quot; /&gt;
      &lt;/w:t&gt;
    &lt;/w:r&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre></p>
<p> </p>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=48&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/02/12/how-to-transform-infopath-2007-form-data-into-a-word-2007-document-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
		<item>
		<title>Don&#8217;t use Port 8082 for SharePoint web applications</title>
		<link>http://benny56sp.wordpress.com/2010/02/06/dont-use-port-8082-for-sharepoint-web-applications/</link>
		<comments>http://benny56sp.wordpress.com/2010/02/06/dont-use-port-8082-for-sharepoint-web-applications/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 11:16:48 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Troubleshooting]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=42</guid>
		<description><![CDATA[When you setup a web application with SharePoint Server 2007 at port 8082 you will significantly slow down your server. Other symptoms of doing something wrong: Either the &#8220;DC Launcher&#8221; service will not start or the web application on port 8082 is down. Unfortunatelly you can start both manually and all seems to be okay. Reason The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=42&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>When you setup a web application with SharePoint Server 2007 at port 8082 you will significantly slow down your server.</p>
<p>Other symptoms of doing something wrong: Either the &#8220;DC Launcher&#8221; service will not start or the web application on port 8082 is down. Unfortunatelly you can start both manually and all seems to be okay.</p>
<p><strong>Reason</strong></p>
<p>The Document Conversion Launcher service is already listing to port 8082. You may not have two listeners to the same port.</p>
<p><strong>Workaround</strong></p>
<p>I guess that the best practice will be to relocate the web application to another port. Simply create a new web application at the desired port (other than port 8082), detach the content database of the old web application and attach it at the new one.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=42&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/02/06/dont-use-port-8082-for-sharepoint-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
		<item>
		<title>How to update all library&#8217;s InfoPath forms after relocation</title>
		<link>http://benny56sp.wordpress.com/2010/02/05/how-to-update-all-librarys-infopath-forms-after-relocation/</link>
		<comments>http://benny56sp.wordpress.com/2010/02/05/how-to-update-all-librarys-infopath-forms-after-relocation/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 18:34:02 +0000</pubDate>
		<dc:creator>Bernhard</dc:creator>
				<category><![CDATA[Admin tools]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[InfoPath 2007]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Admin]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[InfoPath]]></category>

		<guid isPermaLink="false">http://benny56sp.wordpress.com/?p=5</guid>
		<description><![CDATA[There are several ways to move a form library to another web or server. In my case I setup a new SharePoint 2007 server, defined a new web application and attached the original content database to it. Problem After shutting down the old server the InfoPath forms of a form library were not accessible anymore, because the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=5&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are several ways to move a form library to another web or server. In my case I setup a new SharePoint 2007 server, defined a new web application and attached the original content database to it.</p>
<p><strong>Problem</strong></p>
<p>After shutting down the old server the InfoPath forms of a form library were not accessible anymore, because the template was also shut down together with the server and there was no other copy in the network known by the InfoPath framework. Therefore InfoPath couldn&#8217;t show the form. So what to do?</p>
<p>An InfoPath form is a xml file having a couple of processing-instuctions in its header. Example:</p>
<p><pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;?mso-infoPathSolution solutionVersion=&quot;1.0.0.121&quot; productVersion=&quot;12.0.0&quot; PIVersion=&quot;1.0.0.0&quot; href=&quot;http://www.domain.de/FormServerTemplates/MyForm.xsn&quot; name=&quot;urn:schemas-microsoft-com:office:infopath:MyForm:http---www-domain-de-MyForm&quot; language=&quot;de&quot; ?&gt;
&lt;?mso-application progid=&quot;InfoPath.Document&quot; versionProgid=&quot;InfoPath.Document.2&quot;?&gt;
... form data go here ...

</pre></p>
<p>The processing instruction &#8220;mso-infoPathSolution&#8221; contains a href attribute which points to the form template. In my case the href points to the Forms Server. The form template must be accessible by InfoPath to open the form.</p>
<p><strong>Task</strong></p>
<p>Update the template references of all forms!</p>
<p><strong>Solution</strong></p>
<p>Since I do a lot of my SharePoint administration stuff  with batch files, I wrote the console application &#8220;UpdateIPFormTemplateLocation&#8221;.</p>
<p style="text-align:left;"><strong>Usage:  UpdateIPFormTemplateLocation.exe -web [web url]  -lib [library name] -loc [form template url]</strong></p>
<p style="text-align:left;">Example: UpdateIPFormTemplateLocation.exe -web http://www.yourdomain.com/yourweb -lib yourlibname -loc http://www.anotherdomain.com/FormServerTemplates/MyForm.xsn</p>
<p>The complete C# source code is listed below. I guess it is self explaining.</p>
<p><strong>Conclusion</strong></p>
<p>The tool &#8220;UpdateIPFormTemplateLocation&#8221; (see source code below) updates the references of InfoPath forms to their template. It is useful after relocation of form libraries or template libraries.</p>
<p>Before running the tool you should check associated workflows. Workflows may be attached to the form library or the form&#8217;s content type and may be triggered by updating the forms. If you don&#8217;t want further actions by workflows while updating you need to disable the workflows before you start the tool. After all done renable the workflows again.</p>
<p>You may also slightly modify the source code to update any data fields of InfoPath forms. </p>
<p>Hope it helps and feel free to improve my solution.</p>
<p><pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Xml;
using Microsoft.SharePoint;
namespace UpdateIPFormTemplateLocation
{
    /// &lt;summary&gt;
    /// This tool updates all InfoPath forms of a form library after
    /// the library has been relocated to another server or web.
    /// The update adjusts the &quot;href&quot; attribute of the form's
    /// processing-instruction to new location of the form template.
    /// &lt;/summary&gt;
    class Program
    {
        /// &lt;summary&gt;
        /// Thread sleep time [ms] after one form has been updated
        /// &lt;/summary&gt;
        private static int _SleepTime = 5000;
        /// &lt;summary&gt;
        /// Main entry
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;args&quot;&gt;command line parameters&lt;/param&gt;
        /// &lt;returns&gt;error code. 0=no error. 1=error detected.&lt;/returns&gt;
        static int Main(string[] args)
        {
            // Parse command line
            Dictionary parameters = ParseCommandLine(args);

            try
            {
                // Update all forms in library
                UpdateForms(parameters);
                Console.WriteLine(&quot;Done.&quot;);
                return 0;
            }
            catch (KeyNotFoundException)
            {
                // Command line error
                Console.WriteLine(&quot;Usage: UpdateIPFormTemplateLocation.exe -web [web url] -lib [library name] -loc [form template url]&quot;);
                Console.WriteLine(&quot;Example: UpdateIPFormTemplateLocation.exe -web http://www.yourdomain.com/yourweb -lib yourforms -loc http://www.anotherdomain.com/MyForm.xsn&quot;);
                Console.WriteLine(&quot;Execution aborted.&quot;);
                return 1;
            }
            catch (Exception e)
            {
                // Execution error
                Console.WriteLine(e.Message);
                Console.WriteLine(&quot;Execution aborted.&quot;);
                return 1;
            }
        }
        /// &lt;summary&gt;
        /// Update all forms of a form library
        /// &lt;/summary&gt;
        private static void UpdateForms(Dictionary parameters)
        {
            // Get site
            string absWebUrl = parameters[&quot;web&quot;];
            string libName = parameters[&quot;lib&quot;];
            string templateUrl = parameters[&quot;loc&quot;];

            // Open site
            using (SPSite site = new SPSite(absWebUrl))
            {
                // Get site relative web url
                string webUrl = absWebUrl.Replace(site.Url, &quot;&quot;);

                // Open web
                using (SPWeb web = site.OpenWeb(webUrl))
                {
                    // Walk through the library
                    SPDocumentLibrary lib = web.Lists[libName] as SPDocumentLibrary;
                    foreach (SPListItem item in lib.Items)
                    {
                        // Update the InfoPath form
                        UpdateForm(item, templateUrl);

                        // Sleep a little bit to give others a chance too
                        Thread.Sleep(_SleepTime);
                    }
                }
            }
        }
        /// &lt;summary&gt;
        /// Update an InfoPath form
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;item&quot;&gt;the InfoPath form&lt;/param&gt;
        /// &lt;param name=&quot;formTemplateUrl&quot;&gt;the InfoPath form template location&lt;/param&gt;
        private static void UpdateForm(SPListItem item, string formTemplateUrl)
        {
            // Output progress message
            Console.WriteLine(&quot;Updating \&quot;&quot; + item.File.Name + &quot;\&quot; ...&quot;);

            // Create new xml document
            XmlDocument form = new XmlDocument();

            // Load InfoPath form
            using (MemoryStream inStream = new MemoryStream(item.File.OpenBinary()))
            {
                form.Load(inStream);
            }

            // Replace form template url
            ReplaceTemplateReference(form, formTemplateUrl);

            // Save document
            using (MemoryStream outStream = new MemoryStream())
            {
                form.Save(outStream);
                outStream.Seek(0, SeekOrigin.Begin);
                item.File.SaveBinary(outStream);
            }
        }
        /// &lt;summary&gt;
        /// Replace the form template reference of an InfoPath form
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;form&quot;&gt;the InfoPath form&lt;/param&gt;
        /// &lt;param name=&quot;formTemplateUrl&quot;&gt;url of the form template&lt;/param&gt;
        private static void ReplaceTemplateReference(XmlDocument form, string formTemplateUrl)
        {
            // Select the InfoPath processing-instruction (pi)
            XmlNode pi = form.SelectSingleNode(&quot;processing-instruction('mso-infoPathSolution')&quot;);

            // Parse the pi value and replace the href attribute value
            string[] attrs = pi.Value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            string newPiValue = string.Empty;
            foreach (string attr in attrs)
            {
                // Insert separator
                newPiValue += &quot; &quot;;

                // If href attribute replace value otherwise keep all
                newPiValue += (attr.StartsWith(&quot;href&quot;)) ? &quot;href=\&quot;&quot; + formTemplateUrl + &quot;\&quot;&quot; : attr;
            }

            // Set new pi value
            pi.Value = newPiValue.Trim();
        }
        /// &lt;summary&gt;
        /// Parse command line parameters
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;args&quot;&gt;command line parameters&lt;/param&gt;
        /// &lt;returns&gt;parsed command line&lt;/returns&gt;
        private static Dictionary ParseCommandLine(string[] args)
        {
            Dictionary&lt;string, string&gt; dictionary = new Dictionary&lt;string, string&gt;();
            for (int i = 0; i &lt; args.Length; i++)
            {
                if (args[i].StartsWith(&quot;-&quot;) &amp;&amp; i + 1 &lt; args.Length)
                {
                    // Add parameter name and its value to dictionary
                    dictionary.Add(args[i].Substring(1).ToLower(), args[++i]);
                }
            }

            //Done
            return dictionary;
        }
    }
}

</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benny56sp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/benny56sp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/benny56sp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/benny56sp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/benny56sp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/benny56sp.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/benny56sp.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/benny56sp.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=benny56sp.wordpress.com&amp;blog=11862948&amp;post=5&amp;subd=benny56sp&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://benny56sp.wordpress.com/2010/02/05/how-to-update-all-librarys-infopath-forms-after-relocation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b004eb70aa17d6bfa2d022e588d7b0b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">benny56sp</media:title>
		</media:content>
	</item>
	</channel>
</rss>
