|
-
Jul 29th, 2005, 06:59 AM
#1
Thread Starter
Lively Member
Double execute
I am having troubles writing to a CSV file, as VB.NET seems to think it is already in use by another app...
Here is a quick cut down version of the code:
VB Code:
Dim di As New FileInfo("users.csv")
If di.Length <> 0 Then
Dim userFile As New IO.StreamWriter("users.csv", True)
userFile.Write("here is some text, and here is more")
userFile.Close()
End If
If required, I can post the entire chunk, but from what you see above, is there any reason why VB.NET will not write to users.csv?
Cheers.
-
Jul 29th, 2005, 10:09 AM
#2
Fanatic Member
Re: Double execute
Hey...
I tried..
Code:
Dim di As New System.IO.FileInfo(Application.StartupPath & "\users.csv")
If di.Length = 0 Then
Dim userFile As New IO.StreamWriter(Application.StartupPath & "\users.csv",true)
userFile.Write("here is some text, and here is more")
userFile.Close()
End If
But,It works fine for me this way..the text gets added..I find no problem..I just created a file..users.csv..thats all I wonder what problem its giving u...
-
Jul 29th, 2005, 10:14 AM
#3
Fanatic Member
Re: Double execute
Hey..
Maybe you didnt close the stream somewhere else in the program 
Godwin
-
Jul 29th, 2005, 10:19 AM
#4
Thread Starter
Lively Member
Re: Double execute
OK here is a more detailed chunk:
VB Code:
Dim fileResume As Boolean
If System.IO.File.Exists("users.csv") Then
Dim di As New FileInfo("users.csv")
If di.Length <> 0 Then
' Resume File
fileResume = True
Dim Form2 As New Form2
'Dim csvFile As String
'Dim csvBank As String
If Form2.ShowDialog() = DialogResult.OK Then
csvFile = Form2.listItem
csvBank = Form2.newBank
frm3File = Form2.Frm3File
frm3User = Form2.Frm3User
End If
If csvBank = "New Project" Then
fileResume = False
MessageBox.Show(csvFile, "filename")
Dim userFile As New IO.StreamWriter("users.csv", True)
Dim m_today As Date
m_today = Date.Today
userFile.Write(m_today & "," & frm3User & "," & frm3File & ".csv")
userFile.Close()
csvFile = frm3File
Else
fileResume = True
Dim commaseparator As Char() = ","
Dim srd As StreamReader = Nothing
Try
srd = New StreamReader(csvFile)
line = srd.ReadLine()
While Not (line Is Nothing)
fields = line.Split(commaseparator)
If fields.Length <> 3 Then
GoTo ContinueWhile4
End If
Dim qe As QuestionElement
For Each qe In gt
If qe.Id = Int32.Parse(fields(1)) Then
qe.Answered = True
End If
Next qe
ContinueWhile4:
line = srd.ReadLine()
End While
Catch
Finally
If Not (Nothing Is srd) Then
CType(srd, IDisposable).Dispose()
End If
End Try
End If
End If
Else
'Dim m_fileUsers As New IO.StreamWriter("users.csv")
Dim m_today As Date
m_today = Date.Today
Dim myForm3 As New Form3
If myForm3.ShowDialog() = DialogResult.OK Then
csvFile = myForm3.MyFilename
End If
csvFile = csvFile & ".csv"
Dim m_fileUsers As New IO.StreamWriter("users.csv")
m_fileUsers.Write(m_today & "," & myForm3.MyUsername & "," & myForm3.MyFilename & ".csv")
m_fileUsers.Close()
End If
Basically, it won't let me write to users.csv
-
Jul 29th, 2005, 09:23 PM
#5
Fanatic Member
Re: Double execute
Hey Cd...
I wonder if uve declared csvfile,frm3file,frm3user as string or something else..
And in the 1st part of the if statements,ur not using filestreams...
To avoid all this errors,just use filestreams everywhere...open it while writing to it and then close it..
In this case,I think the file is getting locked and isnt released 
Godwin
P.S:I really dont understand what this code actually is...but,i think in the stuff in the beginning have no filestreams..
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
|