ByteScout Invoice Parser SDK - C# - Parse Folder With Invoices To CSV - ByteScout

ByteScout Invoice Parser SDK – C# – Parse Folder With Invoices To CSV

  • Home
  • /
  • Articles
  • /
  • ByteScout Invoice Parser SDK – C# – Parse Folder With Invoices To CSV

How to parse folder with invoices to CSV in C# with ByteScout Invoice Parser SDK

Write code in C# to parse folder with invoices to CSV with this step-by-step tutorial

Learn how to parse folder with invoices to CSV in C# with this source code sample. ByteScout Invoice Parser SDK is the automatic invoice parsing engine and data extraction SDK. Relies on the built-in database and supports thousands of vendors out of the box! Can work offline and can detects and extract company name, invoice number, date, total amount to be paid and other fields. The database of supported invoices is updated on regular basis. Data output can be exported in JSON, XML, CSV formats or directly integrated with other apps. It can parse folder with invoices to CSV in C#.

This code snippet below for ByteScout Invoice Parser SDK works best when you need to quickly parse folder with invoices to CSV in your C# application. This C# sample code is all you need for your app. Just copy and paste the code, add references (if needs to) and you are all set! Use of ByteScout Invoice Parser SDK in C# is also explained in the documentation included along with the product.

Trial version of ByteScout Invoice Parser SDK can be downloaded for free from our website. It also includes source code samples for C# and other programming languages.

Try it today: Get 60 Day Free Trial or sign up for Web API

ParseFolderToCSV.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{D674E35B-D877-45FC-A459-6CEF673CF427}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>ParseFolderToCSV</RootNamespace> <AssemblyName>ParseFolderToCSV</AssemblyName> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <Deterministic>true</Deterministic> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="ByteScout.InvoiceParser, Version=1.0.0.100, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\ByteScout Invoice Parser SDK\net40\ByteScout.InvoiceParser.dll</HintPath> </Reference> <Reference Include="ByteScout.InvoiceParser.Templates, Version=1.0.0.100, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\ByteScout Invoice Parser SDK\net40\ByteScout.InvoiceParser.Templates.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup /> <ItemGroup> <Content Include="..\..\AmazonAWS.pdf"> <Link>invoices\AmazonAWS.pdf</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="..\..\DigitalOcean.pdf"> <Link>invoices\DigitalOcean.pdf</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> <Content Include="..\..\Google.pdf"> <Link>invoices\Google.pdf</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

ParseFolderToCSV.sln
      
Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28010.2016 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParseFolderToCSV", "ParseFolderToCSV.csproj", "{D674E35B-D877-45FC-A459-6CEF673CF427}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {D674E35B-D877-45FC-A459-6CEF673CF427}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D674E35B-D877-45FC-A459-6CEF673CF427}.Debug|Any CPU.Build.0 = Debug|Any CPU {D674E35B-D877-45FC-A459-6CEF673CF427}.Release|Any CPU.ActiveCfg = Release|Any CPU {D674E35B-D877-45FC-A459-6CEF673CF427}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EDCD81CC-A538-41D3-A99A-0F287E9FC614} EndGlobalSection EndGlobal

Try it today: Get 60 Day Free Trial or sign up for Web API

Program.cs
      
using System; using System.Diagnostics; using System.Text; using ByteScout.InvoiceParser; namespace ParseFolderToCSV { class Program { static void Main(string[] args) { string inputFolder = @".\invoices"; string outputFile = @".\result.csv"; // Create InvoiceParser instance using (InvoiceParser parser = new InvoiceParser("demo", "demo")) { // Disable fallback to default generic template if document is nor recognized parser.FallbackToGenericTemplate = false; // Setup CSV output CSVOptions csvOptions = new CSVOptions { Encoding = Encoding.UTF8, SeparatorCharacter = ",", QuotationCharacter = "\"", UnwrapMultilineValues = true }; // Parse all document in input folder and save results to CSV file BatchProcessing.ParseFolderToCSV(parser, inputFolder, outputFile, csvOptions, ProcessingCallback); } // Open generated CSV file in default associated application (for demo purpose) Process.Start(outputFile); } /// <summary> /// Callback method to display progress and interrupt processing if needed. /// </summary> /// <param name="fileName">File name.</param> /// <param name="parsingResult">Parsing result.</param> /// <param name="progress">Current progress in percents.</param> /// <param name="innerException">Exception information in case of error.</param> /// <param name="cancel">Set to <c>true</c> to interrupt the batch processing.</param> static void ProcessingCallback(string fileName, bool parsingResult, double progress, Exception innerException, ref bool cancel) { Console.WriteLine({code}quot;{progress}% Processed file \"{fileName}\""); Console.WriteLine({code}quot; Result: {parsingResult}"); if (!parsingResult) { if (innerException != null) Console.WriteLine(innerException.ToString()); Console.Write("Continue processing? (y/n): "); int key = Console.Read(); if (key == 'n') { Console.WriteLine("Interrupted."); cancel = true; } } } } }

Try it today: Get 60 Day Free Trial or sign up for Web API

MORE INFORMATION

Get 60 Day Free Trial or Visit ByteScout Invoice Parser SDK page

Explore ByteScout Invoice Parser SDK documentation

WEB API VERSION

Sign Up for free Web API key

Explore Web API Documentation

prev
next