Create a New Project

  1. Create a new Console Project in Visual Studio.
  2. Follow the steps in the Install EdiFabric article to install EdiFabric (paid or trial version) to the project.
  3. Install the EDI templates.
    1. For the trial version

      Install the NuGet package for the EDI standard you are interested in, e.g., if you want to translate from X12/HIPAA files, then install EdiFabric.Templates.X12, if you want to translate from EDIFACT/EANCOM files, then install EdiFabric.Templates.Edifact. Let's translate an X12 file:

      nuget-templates-trial.png

      Your project references should look like this:

      edifabric-trial-project.png

    2. For the paid version

      Create a new class library project, regardless of whether it is .NET Core or .NET Framework, the NuGet package will resolve itself to the correct target.

      Remove the default Class1.cs.

      (.NET Framework only) Add references to System.Runtime.Serialization and System.Xml.Serialization.

      Navigate to the EdiFabric.Templates.Enterprise or the EdiFabric.Templates.Professional folder you downloaded. Add only the EDI templates (C# files) you need to use (in this example it is 850, version 4010, standard X12), together with all the files in the Common folder to that project as existing files:

      edifabric-x12-templates.png

      NOTE:

      The common files are the 5 files ending with: _Codes.cs _ComplexElementInterfaces.cs _ComplexElements.cs _SegmentInterfaces.cs _Segments.cs

      Add a project reference in the Console Project to the Class Library project.

      Your project references should look like this:

      edifabric-full-project.png

  4. Open Program.cs and paste the following code, overwriting the existing:
    1. For the trial version

      using EdiFabric.Core.Model.Edi;
      using EdiFabric.Framework.Readers;
      using System.Collections.Generic;
      using System.IO;
      using System.Linq;
      
      namespace ConsoleApp
      {
          class Program
          {
              static void Main(string[] args)
              {
      var x12File = File.OpenRead(@"{Path to X12 file}"); var serialKey = File.ReadAllText(@"{Path to serial.key file}").Trim();

      EdiFabric.SerialKey.Set(serialKey); List<IEdiItem> ediItems; using (var reader = new X12Reader(x12File, "EdiFabric.Templates.X12", new X12ReaderSettings {ContinueOnError = true })) { ediItems = reader.ReadToEnd().ToList(); } } } }

      Change variable serialKey to point to the file serial.key in folder edifabric-trial.

    2. For the paid version

      using EdiFabric.Core.Model.Edi;
      using EdiFabric.Framework.Readers;
      using System.Collections.Generic;
      using System.IO;
      using System.Linq;
      
      namespace ConsoleApp
      {
          class Program
          {
              static void Main(string[] args)
              {
      var x12File = File.OpenRead(@"{Path to X12 file}");

      EdiFabric.SerialKey.Set("{Your serial key}"); List<IEdiItem> ediItems; using (var reader = new X12Reader(x12File, "ClassLibrary1", new X12ReaderSettings {ContinueOnError = true })) { ediItems = reader.ReadToEnd().ToList(); } } } }

      Set the serial key to the serial key you received when you ordered a plan.

  5. Rebuild the solution to install the rest of the dependencies. If there are any build errors, contact us for assistance.
  6. Change variable x12File to point to the file you want to translate from EDI.
  7. Add a breakpoint and run the console app in debug mode to inspect ediItems:

    mceclip6.png

Was this article helpful?
0 out of 0 found this helpful