Using XSLT transform we can convert infopath form to HTML content.
Creating the XSL file form infopath form
- Open infopath form using Infopath form designer.
- Go to File -> Click on ‘Save as Source files’ menu will ask for location. Save the content
- Goto saved location and you can find views.xsl file, It will be in XSLT format.
- Copy the views.xsl file to sharepoint 12hive Layout folder.
Below c# method used to convert xsl file to HTML.
public XslCompiledTransform getXSLTemplate(SPSite Site, string templateName)
{
XslCompiledTransform transform = new XslCompiledTransform();
try
{
//Reading the Template
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
Stream stream = client.OpenRead(Site.RootWeb.Url + "/_layouts/" + templateName + ".xsl")
// load stylesheet into the transformer
using (XmlTextReader stylesheet = new XmlTextReader(stream))
{
transform.Load(stylesheet);
}
stream.Close();
}
catch (Exception ex){throw ex} return transform;
}
Calling below method will return the html string XslCompiledTransform transform = getXSLTemplate(page, templateName);
StringWriter sWriter = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(sWriter);
// read the contents (XML) out of the InfoPath form
using (XmlReader reader = new XmlTextReader(spFile.OpenBinaryStream()))
{
XmlTextWriter results = new XmlTextWriter(writer.InnerWriter);
// Perform the transformation
transform.Transform(reader, results);
reader.Close();
}
That’s it......
No comments:
Post a Comment