Generate EDIFACT UNA

Download EDIFACT UNA C# Sample

You don't have to explicitly generate UNA segment. EdifactWriter will automatically detect if the separators are different than the default and will write the final message with the correct UNA.

If you want to write UNA explicitly then use the Write() overload which takes UNA as a parameter.

To create a UNA, you can either manually populate it, or use the ToUna() method of the Separators object.

 var invoice = EdifactTransactionBuilders.BuildInvoice("1");

 using (var stream = new MemoryStream())
 {
	using (var writer = new EdifactWriter(stream))
	{
		//  Set a custom segment separator
		var separators = new Separators('|', 
                          Separators.Edifact.ComponentDataElement,
			  Separators.Edifact.DataElement, 
                          Separators.Edifact.RepetitionDataElement, 
                          Separators.Edifact.Escape);

                //  Write custom UNA
		writer.Write(separators.ToUna());

		//  Write the UNB with the custom separator set
		writer.Write(SegmentBuilders.BuildUnb("1"), separators);
		writer.Write(invoice);
	}
 }
Was this article helpful?
1 out of 1 found this helpful