I'm an intermediate VB.Net programmer and I need assistant to get a project done. I have a request as follows.
1. Confirm that source files exist (the text files)
Obtain value of field, Location in File_Locations table where code = 'TEST'. If the source files don't exists in this location then end the processing, else proceed to 2 below.
2.Build File Name
Obtain value of the these fields from Control_Table; File_Base, FileSeqNo, FileSuffix. And create the filename as File_Base_FileSeqNo_FileSuffix.
3 Write the Header and Footer details to file created in 2 above. These are new details like the date processed, etc.
4. Write the Actual Message to the file created in 2 above.
For each file in location where Code = 'TEST'
If row exists in Source file copy the contents separated by $ onto the file created in 2 above, and include the new header and footer details.
Note that there will be several files in the source location but each must be copied to a new file created as in 2 above.
I just did a bit of the coding as follows but I'm stuck with this so please assist.
Actually the code belwo is working but when it's trying to write to the file created in 2 it's saying the file is in use by another process and can't be accessed.
Dim imf As String = das.CheckIMFLocation("TEST")
Dim imfp As String = das.CheckIMFLocation("TESTP")
Dim intInFiles As Integer = 0
Dim filename As String = Nothing
Dim di As New DirectoryInfo(imf)
Dim fiArr As FileInfo() = di.GetFiles()
diInward = New DirectoryInfo(imf)
fiInward = diInward.GetFiles("*.txt")
intInFiles = fiInward.Length
Dim FESFileNameInwardBase As String
Dim FESFilenameInwardCurSeqNo As String
Dim FESFileNameInwardSuffix As String
Dim ProcessedFileName As String
Dim createfile As String
Dim fs As FileStream = Nothing
Dim objStreamWriter As StreamWriter
FESFileNameInwardBase = das.ReturnWFControls.FES_Filename_Inward_Base
FESFilenameInwardCurSeqNo = das.ReturnWFControls.FES_Inward_Current_Seq_No
FESFileNameInwardSuffix = das.ReturnWFControls.FES_Filename_Inward_Suffix
If intInFiles > 0 Then
For Each disfri In fiArr
FESFileNameInwardBase = das.ReturnWFControls.FES_Filename_Inward_Base FESFilenameInwardCurSeqNo = das.ReturnWFControls.FES_Inward_Current_Seq_No FESFileNameInwardSuffix = das.ReturnWFControls.FES_Filename_Inward_Suffix ProcessedFileName = FESFileNameInwardBase & "_" & FESFilenameInwardCurSeqNo & "_" & FESFileNameInwardSuffix
createfile = imfp & "\" & ProcessedFileName & ".txt"
fs = File.Create(createfile)
Using MyReader As New TextFieldParser(imf & "\" & disfri.Name)
MyReader.TextFieldType = FileIO.FieldType.Delimited
Dim currentRow As String()
While Not MyReader.EndOfData
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
objStreamWriter = New StreamWriter(createfile)
Catch ex As Exception
MessageBox.Show("Line " & ex.Message & _
"is not valid and will be skipped.")
MessageBox.Show("No Files exist", "No File", MessageBoxButtons.OK, MessageBoxIcon.Stop)