Results 1 to 5 of 5

Thread: [RESOLVED] Getting an Error - Be Gentle, I'm Rusty!

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Resolved [RESOLVED] Getting an Error - Be Gentle, I'm Rusty!

    I'm new to VB.NET (which I'm sure you're tired of hearing me say by now if you frequent the boards!), and I'm a bit rusty on my VB6 also so please, bare with me.

    I'm in the midst of writing a program that loads text files from a directory into our Oracle database.

    I've setup a test directory ("C:\TEST DIR") and placed a few files in it, but I'm having a bit of trouble. In the code below, I connect to our database (names altered), and I point the program to where my files are stored - I think I've done that correctly. The problem occurs when the code hit's the line below highlighted in red. The error that pops up says:

    FILENOTFOUNDException Was unhandled
    'C:\Documents and Settings\TheGrudge\Desktop\BoardLoading\BoardLoading\bin\Debug\Sample.txt"

    How did it end up there? My file is called Sample.txt but it's not there, it's in a folder called TEST DIR??

    Code:
    Public Class frmMain
        Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Create connection object
            Dim OraDB As String = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname) " & _
                                  "(PORT=1xxx)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=server.server.com))); " & _
                                  "User Id=/;Password=/;"
            Dim conn As New OracleConnection(OraDB)
            conn.ConnectionString = OraDB
            conn.Open()
    
            Dim folderInfo As New IO.DirectoryInfo("C:\TEST DIR")
            Dim arrFilesInFolder() As IO.FileInfo
            Dim fileInFolder As IO.FileInfo
    
            arrFilesInFolder = folderInfo.GetFiles("*.txt")
            For Each fileInFolder In arrFilesInFolder
                LoadFile(fileInFolder)
            Next
        End Sub
    
        Public Sub LoadFile(ByVal fileInFolder)
            Dim oFile As System.IO.File
            Dim oRead As System.IO.StreamReader
            Dim strArray() As String
            Dim strPatientType As String
            Dim strFinancialMismatch As String
    
            oRead = oFile.OpenText(fileInFolder)
            'Grab the date-time stamp from the text-file that's being loaded. This will tell us when the data was dumped.
            Dim dtFileCreationDate As Date = System.IO.File.GetCreationTime(fileInFolder)
    
            'Read file line by line using the "streamreader" until the end is reached.
            Do While oRead.Peek <> -1
                'Break the line up into peices and put into an array. The statement below searches for a pipe "|" and puts the fields into 
                'the array automatically.
                strArray = oRead.ReadLine.Split(New C

  2. #2

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Getting an Error - Be Gentle, I'm Rusty!

    Think I fixed it. It should read:

    Code:
     oRead = fileInFolder.OpenText()
    Not

    Code:
    oRead = oFile.OpenText(fileInFolder)
    However in doing so, this line no longer works:

    Code:
    Dim dtFileCreationDate As Date = System.IO.File.GetCreationTime(fileInFolder)
    I will troubleshoot and post back if I get it.

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Getting an Error - Be Gentle, I'm Rusty!

    this works:

    vb Code:
    1. oRead = IO.File.OpenText(fileInFolder)

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    22

    Re: Getting an Error - Be Gentle, I'm Rusty!

    Code:
    Public Sub LoadFile(ByVal fileInFolder)
    any reason you're not passing fileInFolder as type IO.FileInfo?

    then you could get the creation time using the following

    Code:
    fileInFolder.CreationTime

  5. #5

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Getting an Error - Be Gentle, I'm Rusty!

    Quote Originally Posted by morethantoast View Post
    Code:
    Public Sub LoadFile(ByVal fileInFolder)
    any reason you're not passing fileInFolder as type IO.FileInfo?

    then you could get the creation time using the following

    Code:
    fileInFolder.CreationTime
    The reason was pure oversight. That's better.

    Thanks MTM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width