How to create identified document in Sense/Net

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned

Overview

Sense/Net provides you the possibility to add unique identification items to your documents in a couple of ways. You can either apply a watermark (available in the Enterprise Edition), or you can attach an individually developed tool as described in the following.

Steps

1. Create an MS Word form-document

Identified documents in your Sense/Net solution can be downloaded from your document library with the required unique data. For this first you need to create a docx template in MSWord. Open MS Word, and turn on the developer tab in the toolbar:

Word Options

Create a docx template: fill your new document and add „Section Content Controls” to where you want to place unique content later. Add fields you want your users to fill out through Sense/Net:

Developer Toolbar

You need to add Title and Tag-property to all content controls in design-mode. Just right-click on each control, and chose „Properties”, than fill „Title” and „Tag” fields on the popup:

Properties

Upload your finished docx template under as ExampleForm.docx in the following folder: /Root/YourContents/

2. Upload the code-base

You need to embed third-party references: add the following new dll-s to your solution in the /References/ folder in your solution:

Third Party dll files


3. Add a new cs file

Add a new cs-file to your code-base, into the WebSite/Code/ folder; that includes the third-party dll-s and the fields from your docx template:

using DocxTemplateFiller;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace WebSiteProject.Code
{
    public class ExampleForm
    {
        [WordFieldId("NameField")]
        public string NameField { get; set; }
        [WordFieldId("AddressField")]
        public string AddressField { get; set; }
        [WordFieldId("BirthField")]
        public string BirthField { get; set; }
        [WordFieldId("EmailField")]
        public string EmailField { get; set; }
        [WordFieldId("PhoneField")]
        public string PhoneField { get; set; }
    }
}


4. Add a new renderer to your solution

Create a new renderer, which will display the reqired fields with a User control Portlet. It must contain the namespaces from previous dll-s and the exact path of the docx tamplate ("/Root/YourContents/ExampleForm.docx in our case):

<%@ Control Language="C#" AutoEventWireup="true" Inherits="System.Web.UI.UserControl" %>
<%@ Import Namespace="DocxTemplateFiller" %>
<%@ Import Namespace="WebSiteProject.Code" %>
<div class="row">
    <label>NameField</label>
    <asp:TextBox ID="tbNameField" runat="server"></asp:TextBox>
</div>
<div class="row">
    <label>AddressField</label>
    <asp:TextBox ID="tbAddressField" runat="server"></asp:TextBox>
</div>
<div class="row">
    <label>BirthField</label>
    <asp:TextBox ID="tbBirthField" runat="server"></asp:TextBox>
</div>
<div class="row">
    <label>EmailField</label>
    <asp:TextBox ID="tbEmailField" runat="server"></asp:TextBox>
</div>
<div class="row">
    <label>PhoneField</label>
    <asp:TextBox ID="tbPhoneField" runat="server"></asp:TextBox>
</div>
<div class="row">
    <asp:Button Text="Download Docx Form " runat="server" ID="btnOk" OnClick="Click" /><br />
</div>
<script runat="server" type="text/C#">
    protected void Click(object sender, EventArgs e)
    {
        ExampleForm form = new ExampleForm()
        {
            AddressField = tbAddressField.Text,
            BirthField = tbBirthField.Text,
            EmailField = tbEmailField.Text,
            NameField = tbNameField.Text,
            PhoneField = tbPhoneField.Text
        };
DocxTemplateFiller.DocxFiller.DownloadFilledDocxTemplate(HttpContext.Current.Response, "/Root/YourContents/ExampleForm.docx", "form.docx", form);
    }
</script>
<style type="text/css">
    .row{
        display:inline-block;
        width:100%;
        padding:5px;
    }
</style>

5. Build up a Portlet Page

Now you only have to build up your new Portlet Page, where users can connect to the template. Add a new Portlet Page to your site, and include a new User Control Portlet, which uses the custom renderer you created above. Have a look at How to create a simple Portlet Page for more information

User Control Portlet Editor View

Check in your page, and with the use of this Portlet users can add their unique data to the form. By clicking the ’Download’ button, the completed form will be downloaded as a new docx file:

Download Template From Portlet Page

Related links