Products Technologies Demo Docs Blog Support Company

Creating Your First ASP.NET Reporting Application

The MailMerge and ServerTextControl components of TX Text Control .NET Server for ASP.NET enable server-side reporting in Web Forms. A template.docx merges with XML data via a button click handler, and the Page_Load event configures the output, returning the completed result as a PDF.

Creating Your First ASP.NET Reporting Application

Create Your Application

  1. Open Visual Studio and create a new ASP.NET Empty Web Application.

    image

  2. In the Solution Explorer, select the project and choose Add New Item... from the Project main menu.

    In the opened dialog Add New Item, select Web Form and confirm with Add.

    image

  3. In the Solution Explorer, select the newly created Web Form and choose Component Designer from the View main menu.

    Find the MailMerge component in the Toolbox and drag and drop an instance onto the Component Designer form.

    Repeat this step with the ServerTextControl component.

    image

  4. Select the MailMerge component and set the TextComponent property to serverTextControl1 - the name of the inserted instance of ServerTextControl.

    image

  5. While the project is selected in the Solution Explorer, choose Add Existing Item... from the Project main menu.

    In the opened dialog Add Existing Item, browse to the following sample folder:

    %USERPROFILE%\Documents\TX Text Control 29.0.NET Server for ASP.NET\Samples\ASP.NET\CSharp\Documentation Tutorials\MailMerge\Tutorial

    or

    %USERPROFILE%\Documents\TX Text Control 29.0.NET Server for ASP.NET\Samples\ASP.NET\VB.NET\Documentation Tutorials\MailMerge\Tutorial

    Select the following 2 files: template.docx and sample_db.xml and click the Add button.

    image

  6. Select the Web Form in the Solution Explorer and choose Designer from the View main menu.

    Find the Button control in the Toolbox and drag and drop an instance onto the Web Form.

    image

  7. Double-click the button and insert the following code to the event handler:

    protected void Button1_Click(object sender, EventArgs e)
    {
      // create a DataSet from the sample XML data source
      System.Data.DataSet ds = new System.Data.DataSet();
      ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto);
    
      // load the template
      mailMerge1.LoadTemplate(Server.MapPath("template.docx"),
      TXTextControl.DocumentServer.FileFormat.WordprocessingML);
    
      // merge the template with data
      mailMerge1.Merge(ds.Tables[0]);
    
      // save the document as PDF into a byte array
      byte[] data;
      mailMerge1.SaveDocumentToMemory(out data,
      TXTextControl.BinaryStreamType.AdobePDF, null);
    
      // return the document to the browser for download
      Response.Clear();
      Response.AddHeader("content-disposition",
      String.Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"));
      Response.ContentType = "application/pdf";
      Response.BinaryWrite(data);
      Response.End();
    }
    Protected Sub Button1_Click(sender As Object, e As EventArgs)
      ' create a DataSet from the sample XML data source
      Dim ds As New System.Data.DataSet()
      ds.ReadXml(Server.MapPath("sample_db.xml"), System.Data.XmlReadMode.Auto)
    
      ' load the template
      mailMerge1.LoadTemplate(Server.MapPath("template.docx"),
      TXTextControl.DocumentServer.FileFormat.WordprocessingML)
      
      ' merge the template with data
      mailMerge1.Merge(ds.Tables(0))
    
      ' save the document as PDF into a byte array
      Dim data As Byte()
      mailMerge1.SaveDocumentToMemory(data,
      TXTextControl.BinaryStreamType.AdobePDF, Nothing)
    
      ' return the document to the browser for download
      Response.Clear()
      Response.AddHeader("content-disposition",
      [String].Format("attachment;filename={0}", "created_by_txtextcontrol.pdf"))
      Response.ContentType = "application/pdf"
      Response.BinaryWrite(data)
      Response.[End]()
    End Sub
  8. In the same code view, add the following code to the Page_Load event:

    protected void Page_Load(object sender, EventArgs e)
    {
      InitializeComponent();
    }
    Protected Sub Page_Load(sender As Object, e As EventArgs)
      InitializeComponent()
    End Sub
  9. Compile and start the application. Press the button to create the report that is returned as a PDF file.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETDocumentViewerHTML5

Creating an ASP.NET MVC DocumentViewer Application With Razor

Create a simple ASP.NET (MVC) application that uses the HTML5 document viewer.


ASP.NETHTML5Razor

Creating an ASP.NET MVC Application With Razor

This tutorial covers integrating TX Text Control .NET Server for ASP.NET into an ASP.NET MVC application. It walks through installing the TXTextControl.Web NuGet package, creating an MVC 5…


ASP.NETAjaxHTML5

Creating an ASP.NET Web Forms AJAX Application

TX Text Control .NET Server for ASP.NET integrates into Web Forms by dragging the TextControl component from the Visual Studio Toolbox onto a designer form. Setting Dock to Window fills the area.…


ASP.NETReportingAuto Save

Automatically Reconnect to the Server and Recover the Document

When a WebSocket connection drops, the TX Text Control editor automatically reconnects and recovers the document using browser local storage. The implementation saves document state client-side…


ASP.NETReportingTutorial

New Online Sample: Build your First Report

A new interactive online demo walks through building a report with TX Text Control in three steps: preparing JSON data in a live editor, creating a template with merge fields and repeating blocks,…

Share on this blog post on: