|
-
Feb 24th, 2011, 03:36 PM
#1
Thread Starter
Fanatic Member
[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
-
Feb 24th, 2011, 03:43 PM
#2
Thread Starter
Fanatic Member
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.
-
Feb 24th, 2011, 03:46 PM
#3
Re: Getting an Error - Be Gentle, I'm Rusty!
this works:
vb Code:
oRead = IO.File.OpenText(fileInFolder)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 24th, 2011, 03:54 PM
#4
Junior Member
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
-
Feb 25th, 2011, 08:30 AM
#5
Thread Starter
Fanatic Member
Re: Getting an Error - Be Gentle, I'm Rusty!
 Originally Posted by morethantoast
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|