Hello Friends,

I have a patient register form in my project...

When the patient details will be saved in the database it should also be saved in the text file...

I am dynamically creating a folder with patientid and firstname

in that folder I am creating a text file patientreg.txt and it should contain the contents of text file....

I have wriiten the below code but I am getting an error....

Dim di As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\" + txtPatientID.Text + txtFName.Text)
If Not di.Exists Then
   di.Create()
End If
Dim pathreg As String = di.ToString & "\patientreg.txt"
If File.Exists(pathreg) Then
   Debug.Print("True: " + pathreg)
Else
   File.Create(pathreg)
   Debug.Print("False: " + pathreg)
End If
FileClose()
'Dim objWriter As New System.IO.StreamWriter(pathreg, False)
'objWriter.WriteLine(txtPatientID.Text + "*" + txtFName.Text)
'objWriter.Close()
IO.File.AppendAllText(pathreg, txtPatientID.Text + "*" + txtFName.Text)
Debug.Print("di value: " + di.ToString)

Error: The process cannot access the file 'D:\Pooja\CM\Clinical_Management\Clinical_Management\bin\Debug\435sdfs\patientreg.txt' because it is being used by another process.

Can anyone help me out in this...I also added the code to close the file...but still the error is throwing up....

Hello Friends,

I have a patient register form in my project...

When the patient details will be saved in the database it should also be saved in the text file...

I am dynamically creating a folder with patientid and firstname

in that folder I am creating a text file patientreg.txt and it should contain the contents of text file....

I have wriiten the below code but I am getting an error....

Dim di As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\" + txtPatientID.Text + txtFName.Text)
If Not di.Exists Then
   di.Create()
End If
Dim pathreg As String = di.ToString & "\patientreg.txt"
If File.Exists(pathreg) Then
   Debug.Print("True: " + pathreg)
Else
   File.Create(pathreg)
   Debug.Print("False: " + pathreg)
End If
FileClose()
'Dim objWriter As New System.IO.StreamWriter(pathreg, False)
'objWriter.WriteLine(txtPatientID.Text + "*" + txtFName.Text)
'objWriter.Close()
IO.File.AppendAllText(pathreg, txtPatientID.Text + "*" + txtFName.Text)
Debug.Print("di value: " + di.ToString)

Error: The process cannot access the file 'D:\Pooja\CM\Clinical_Management\Clinical_Management\bin\Debug\435sdfs\patientreg.txt' because it is being used by another process.

Can anyone help me out in this...I also added the code to close the file...but still the error is throwing up....

Got the answer

Dim di As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\" + txtPatientID.Text + txtFName.Text)
If Not di.Exists Then
    di.Create()
End If
Dim pathreg As String = di.ToString & "\patientreg.txt"
FileOpen(1, pathreg, OpenMode.Output)
If File.Exists(pathreg) Then
    Debug.Print("True: " + pathreg)
Else
    File.Create(pathreg)
    Debug.Print("False: " + pathreg)
End If
Print(1, txtPatientID.Text + "*" + txtFName.Text)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.