Infopath to WordML using Sharepoint#

For an internal project, I made an InfoPath to WordML converter in Sharepoint. For our case, project references are filled in InfoPath. Sharepoint translates the XML InfoPath documents to XML Word (WordML) documents so they can be used in the Sharepoint proposal accelerator. A nice example of Sharepoint Office integration and business innovation. Let's say..be more productive! ;)

 

Sharepoint WebPart

To do the conversion, I made a simple webpart that picks up the InfoPath documents from a form library, applies an XSLT to them and put them back into a target library in Sharepoint.

Yes, it’s the Dutch version of Sharepoint Portal Server :)

 

To be honest, the code is not that exciting. So, let’s take a look:

 

 

 

SPWeb aWeb = SPControl.GetContextWeb(Context);

aWeb.AllowUnsafeUpdates = true;

SPListCollection myCollection = aWeb.Lists;

myCollection.IncludeRootFolder = true;

// Source and Target library

SPList WordMLList = myCollection[ddlTarget.SelectedItem.Value];

SPList InfoPathList = myCollection[ddlSource.SelectedItem.Value];

// Loop through the files            

foreach (SPListItem myItem in InfoPathList.Items)

{

     SPFile myFile = myItem.File;

     Stream myStream = new MemoryStream(myFile.OpenBinary());

     XmlDocument myDoc = new XmlDocument();

     myDoc.Load(myStream);

     XmlDocument newDoc = new XmlDocument();

     XslTransform xslt = new XslTransform();

     string strXSLT = "/_layouts/Office/InfoPath2WordML.xslt";

     xslt.Load(HttpContext.Current.Server.MapPath(strXSLT));

     // Apply XSLT

     newDoc.Load(xslt.Transform(

          myDoc.CreateNavigator(),

          null,

          new XmlUrlResolver()

          ));

     // Add WordML header                      

     StringBuilder myString = new StringBuilder();

     myString.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><?mso-application progid=\"Word.Document\"?>");

             

     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(myString.ToString() + newDoc.InnerXml);

     SPFileCollection files = WordMLList.RootFolder.Files;

     string newUrl = files.Folder.Url + "/" + myFile.Name;

     // Save file to target library
    
files.Add(newUrl, bytes, true);

}

 

 

Proposal Accelerator

Once we’ve converted the documents into WordML documents, we can use it in the Office Proposal Accelerator. This accelerator is provided by Microsoft to enable productivity when writing proposal documents. The accelerator searches through the WordML documents using an Office Task Pane add-on. With a single click the documents can be inserted into the proposal.

 

What else?

So, what else? The InfoPath project reference can be used in many ways. Using XSLT conversions can be made, but with some more imagination, also other ‘information containers’ can be provided:

 

  • Portfolio items in MCMS for a website (cool, my next project??)
  • Proposals
  • Project Sites in Sharepoint
  • Project data in SQL Server
  • Etc.

 So, this kind of is a higher level of Office productivity and innovation integrating different applications and tools in Sharepoint.

.Net | InfoPath | MCMS | Office | Sharepoint | Tam Tam | Webparts
Thursday, December 23, 2004 7:33:15 AM UTC #    Comments [3]  | 

 

All content © 2010, Mart Muller
On this page
This site
Calendar
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts