---
title: Read an EDI interchange file
summary: Parse a physical EDI file into a populated EdiFile via the EdiManager facade.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common.Files
reference_type: package
operation_id: OP-05
trigger: Caller calls EdiManager.File().Path(path).Read()
---

# Read an EDI interchange file

`EdiManager.File().Path(p).Read()` is the sanctioned entry point for reading an ASC X12 interchange file. It loads the physical file, delegates lexical parsing to `EdiSegmentParser` ([Parse EDI text into segments and elements](parse-edi-text-into-segments-and-elements.md)), and triggers envelope grouping ([Build the X12 envelope hierarchy](build-x12-envelope-hierarchy.md)).

| Field | Value |
| --- | --- |
| **Operation ID** | OP-05 |
| **Trigger** | Caller request. |
| **Inputs** | File path. |
| **Outputs** | Populated `EdiFile` with segments and functional-group hierarchy. |
| **Primary components** | `EdiManager.File()`, `EdiFileBuilder.Path`, `EdiFileBuilder.Read()`, `EdiFileReader.Read()` |
| **Entry point** | `Common\SAIF.Common.Files\Edi\EdiManager.cs`, `Common\SAIF.Common.Files\Edi\Core\Builders\EdiFileBuilder.cs`, `Common\SAIF.Common.Files\Edi\Core\Readers\EdiFileReader.cs` |

## Steps

1. `EdiManager.File()` returns a new `EdiFileBuilder`; `Path(path)` stores the path and returns `this` (fluent).
2. `Read()` constructs `EdiFileReader { Path = path }` and calls `Read()`.
3. Create `EdiFile`, set `FileName` from `new FileInfo(Path).Name`.
4. `File.ReadAllLines(Path)`, then trim and concatenate every line into one continuous string — line breaks in the physical file are not significant ([BR-017](../business-rules.md#br-017-physical-line-breaks-are-not-significant)).
5. `new EdiSegmentParser().Parse(fileData)` — see [Parse EDI text into segments and elements](parse-edi-text-into-segments-and-elements.md).
   > **Origin**: Step 5 delegates lexical parsing to `EdiSegmentParser.Parse`, documented fully in [Parse EDI text into segments and elements](parse-edi-text-into-segments-and-elements.md).
6. `file.SetSegments(segments)` stores the segments and calls `RefreshGroupings()` ([BR-029](../business-rules.md#br-029-first-isa-and-iea-are-the-interchange-header-and-trailer), [BR-030](../business-rules.md#br-030-functional-groups-built-only-when-all-four-control-segments-present)) — see [Build the X12 envelope hierarchy](build-x12-envelope-hierarchy.md).
7. `EdiGroupParser.CreateFunctionalGroups(file)` is called again explicitly — redundant with step 6's conditional call.*

## Process flow

```mermaid
flowchart TD
	Start(["Caller: EdiManager.File().Path(p).Read()"]) --> Read[EdiFileReader.Read]
	Read --> Concat["File.ReadAllLines +<br>trim/concatenate lines"]
	Concat --> Parse["EdiSegmentParser.Parse(fileData)"]
	Parse --> Set["EdiFile.SetSegments"]
	Set --> Refresh["EdiFile.RefreshGroupings"]
	Refresh --> Complete{"ISA, IEA, GS, GE all present?"}
	Complete -->|Yes| Groups["EdiGroupParser.CreateFunctionalGroups"]
	Complete -->|No| Skip[No functional-group tree built]
	Groups --> EndOk([Populated EdiFile returned])
	Skip --> EndOk
```

## Failure and edge-case behavior
- Physical line wrapping has no semantic effect — a file wrapped at 80 characters and the same file on one line parse identically ([BR-017](../business-rules.md#br-017-physical-line-breaks-are-not-significant)).
- If any of `ISA`, `IEA`, `GS`, `GE` is missing, `EdiFile.FunctionalGroups` is left unbuilt rather than raising an error ([BR-030](../business-rules.md#br-030-functional-groups-built-only-when-all-four-control-segments-present)).

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

> **Note:** Statements marked with `*` were inferred from code structure, naming
> conventions, or contextual evidence where direct confirmation was not available
> in source artifacts.

## Sources
- Common\SAIF.Common.Files\Edi\EdiManager.cs
- Common\SAIF.Common.Files\Edi\Core\Builders\EdiFileBuilder.cs
- Common\SAIF.Common.Files\Edi\Core\Readers\EdiFileReader.cs
- Common\SAIF.Common.Files\Edi\EdiFile.cs
