zoukankan      html  css  js  c++  java
  • Infopath form to HTML using csharp 金大昊(jindahao)

    I know converting Infopath form to HTML is pain task. Recently i have worked on one assignment where i need to send infopath form as email. So sending browser based infopath as email content is not possible so i decided to convert Infopath form to HTML and attach to email message. I have tried many method to convert infopath to html but all are ended with pain. At the end i found good solution so we can convert infopath form to html. I would like to share this approach because i’m sure you won’t get good solution by searching internet. Best method is using .net programming and using XSLT transform approach we can convert infopath form to HTML content. You can find the below steps to html conversion.

    Creating the XSL file form infopath form 

    1. Open infopath form using Infopath form designer.
    2. Go to File -> Click on ‘Save as Source files’ menu will ask for location.  Save the content
    3. Goto saved location and you can find views.xsl file, It will be in XSLT format.
    4. 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, Simple isn’t it?  If you found this post useful then you can donate me to encourage writing more articles using below link.

  • 相关阅读:
    shell脚本从文件夹中递归提取文件
    php生成图片缩略图,支持png透明
    shell脚本批量下载资源并保留路径
    PHP字符串word末字符大小写互换
    编译gearman提示缺少boost
    Rebranding(模拟+思维)
    拼接平方数(枚举每个数的组合情况就好)----------蓝桥备战系列
    格子刷油漆(dp)-----------蓝桥备战系列
    高僧斗法(nim博弈)----------蓝桥备战系列
    网络寻路(思维+vector的应用)-----------蓝桥备战系列
  • 原文地址:https://www.cnblogs.com/jindahao/p/2739010.html
Copyright © 2011-2022 走看看