Skip to main content
Windward

Command Line C# Application

Overview

Command Line C# Application

Resolution

Downloads

Creating the code

This document shows how to create your first program using Windward Reports. To keep it very simple it creates a command line application. Windward Reports requires .NET 2.0 and therefore we are using VS 2005.
 

  1. Create a new C# console project. 
    Simple_.NET_Application1.jpg
  2. Which gives us:
    Simple_.NET_Application2.jpg
  3. Add all of the files in the dll subdirectory of Windward Reports as references:
    Simple_.NET_Application3.jpg
  4. Copy the template and data files from C:\Program Files\Windward Studios\Windward Reports .NET Engine\samples\sample1 to the directory with the sample report.
    Simple_.NET_Application4.jpg
    to:
    Simple_.NET_Application5.jpg
  5. Create a SimpleReport.exe.config file and place the license key in it. The license key comes from the email that your key was in:
    Simple_.NET_Application6.jpg
    and goes in the config file:
     
  6. Add a build event xcopy "$(ProjectDir)SimpleReport.exe.config" "$(TargetDir)" /Y so that the config file is copied to the directory the program is run in when you run from VS 2005.
  7. To keep things simple, there is no error checking and this will always create a PDF report. To see a complete version of this simple approach, please look at the downloadable zip file (link above).
  8. Passing templates and xml data to the engine and getting the created report back is all done with streams. So the template and data can come from anywhere and the created report can be passed back to any destination. (SQL data sources is handled via connections.)
  9. Here is the complete code:
    using net.windward.api.csharp;
    using System;
    using System.IO;
    
    namespace SimpleReport
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Initialize the reporting engine.
                Report.Init();
                
                // get the template and output files
                Stream template = new FileStream(args[0], FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                Stream output = new FileStream(args[1], FileMode.Create, FileAccess.Write, FileShare.None);
                Console.Out.WriteLine("Template: {0}", new Object[] { args[0] });
                
                // Create the report object
                Report report = new ReportPdf(template, output);
    
                // parse the template
                report.ProcessSetup();
    
                // process the data
                Stream xml = new FileStream(args[2], FileMode.Open, FileAccess.Read);
                IReportDataSource ds = new XmlDataSourceImpl(xml, false);
                Console.Out.WriteLine("Processing data: {0}", new Object[] { args[2] });
                report.ProcessData(ds, null);
    
                ds.Close();
                xml.Close();
    
                // create the final report
                report.ProcessComplete();
    
                template.Close();
                output.Close();
                
                Console.Out.WriteLine("{0} built, {1} pages long", new Object[] { args[1], report.NumPages });
            }
        }
    }
  10. Run the program as: 
    SimpleReport "Purchase Order Template.rtf" report.pdf order.xml
  11. This will generate the report in the file report.pdf. This is all there is to it, at it’s simplest Windward Reports can be invoked using 13 lines of code, or 8 lines if you don’t include creating and closing all of the streams.
  • Was this article helpful?