VB.Net Code Snippet
Imports System.Windows.Forms
Imports System.Collections.Generic
Public Class Test
Dim mSessionID As String = ""
Dim mLogText As String = ""
Public Sub SendAndReceive()
Dim netEDIService As New netEDI.netEDIcoms.netEDINetwork
AddHandler netEDIService.StatusUpdate, AddressOf CommunicationLog
With netEDIService
If .Login("netEDI.net", "netedi.LTD66") Then
mSessionID = .SessionID 'Store the session ID
'Loop round your list of files to send
If .IsEDIFile("testedi.txt") Then
'if file is EDI use the Upload function
If .Upload("testedi.txt") Then
'Flag the file in your system as sent
Else
'report error to log file and mark file in your system as unsent
MessageBox.Show(.LastError)
End If
Else
'if non-edi file use the UploadEx function to send directly to a Mailbox on the netEDI network
If .UploadEx("Local Path & Filename", "GLN/Other ID", "Qualifer if req.") Then
'Flag the file in your system as sent
Else
'report error to log file and mark file in your system as unsent
MessageBox.Show(.LastError)
End If
End If
'end of loop around files to send
Dim Files As List(Of netEDI.netEDIcoms.netEDIFile) 'Holds a list of Files
Files = .List() 'List Files for Download
If Files.Count > 0 Then
'Files to Download
For Each objFile As netEDI.netEDIcoms.netEDIFile In Files
If .Download(objFile.ID, objFile.ID & ".edi") Then 'Download the EDI file to the file using the Network File ID
.DownloadOK() 'Marks the file as downloaded on the network
Else
'report error with download
MessageBox.Show(.LastError)
End If
Next
End If
Else
'Log error with login
MessageBox.Show(.LastError)
End If
'logout from the service
.Logout()
WriteLog()
End With
End Sub
Private Sub CommunicationLog(ByVal Description As String)
'Display the Description of events on screen to the user and/or write them to a log file
mLogText &= Description & System.Environment.NewLine
End Sub
Private Sub WriteLog()
'Store the log to file
If mSessionID <> "" Then
Dim objStream As New System.IO.StreamWriter(mSessionID & ".log")
objStream.Write(mLogText)
objStream.Close()
End If
End Sub
End Class