Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Being used by another process error

Threaded View

  1. #1

    Thread Starter
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Resolved [RESOLVED] [2005] Being used by another process error

    The problem seems to be with a text file that I'm accessing. I can't figure out where the problem might be. From the code i'm getting errors at
    Error Place 4 and 5 (you will see what i mean by that below). The message says that the file

    (Application.StartupPath & "\UserHistory.txt")

    is being used by another process but I've checked and this is the only code that can access the text file in question. Anyone spot what's the
    matter with it? Here's the relevant code:

    VB Code:
    1. Try
    2.             If System.IO.File.Exists(Application.StartupPath & "\UserHistory.txt") = False Then
    3.                 System.IO.File.Create(Application.StartupPath & "\UserHistory.txt") 'CREATE FILE
    4.             End If     'DO I NEED TO RELEASE THE FILE OR SOMETHING??
    5.         Catch ex As Exception
    6.             MessageBox.Show(ex.Message & "ERROR PLACE 1")
    7.         End Try
    8.  
    9. 'THERE'S CODE HERE TO CHECK THAT ALL FIELDS HAVE BEEN FILLED IN
    10. 'THEN...
    11.  
    12. 'Once TRUE create User Account
    13.         'FIRST CREATE USER FOLDER:
    14.         'DEFINE THE USER FOLDER PATH TO CHECK/CREATE
    15.         Dim userPath As String = Application.StartupPath & "\User Accounts\" & _
    16.         txtSurname.Text.ToLower & "\" & txtCreateUsername.Text.ToLower & "\"
    17.  
    18.         Try
    19.             If Not My.Computer.FileSystem.DirectoryExists(userPath) Then
    20.                 'CREATE FOLDER
    21.                My.Computer.FileSystem.CreateDirectory(userPath)
    22.             ElseIf My.Computer.FileSystem.DirectoryExists(userPath) Then
    23.                 'Check Sub Directory Text File
    24.                 MessageBox.Show("An account with these details already exists." & _
    25.                 "Please select a new username or use the account details finder to" & _
    26.                 "get your existing details", "Account already exists", MessageBoxButtons.OK)
    27.                 txtCreateUsername.Clear()    'Clear & reselect
    28.                 txtCreateUsername.Select()   'username field
    29.                 Exit Sub
    30.             End If
    31.         Catch ex As Exception
    32.             MessageBox.Show(ex.Message & "ERROR PLACE 2")
    33.         End Try
    34.  
    35.         'Once check has been made, create a text file that
    36.         'will contain all the  user details:
    37.         Try
    38.             'Create STREAMWRITER
    39.             Dim sw As New System.IO.StreamWriter(userPath & "\userDetails.txt")
    40.             Dim UserDOB As Date = CDate(cboDay.Text & "/" & cboMonth.Text & "/" & cboYear.Text)
    41.             sw.Write("Surname:" & txtSurname.Text.ToLower & Environment.NewLine)
    42.             sw.Write("First Name:" & txtFirstName.Text.ToLower & Environment.NewLine)
    43.             sw.Write("Occupation:" & cboOccupation.Text.ToLower & Environment.NewLine)
    44.             sw.Write("DOB:" & UserDOB & Environment.NewLine)
    45.             sw.Write("Username:" & txtCreateUsername.Text.ToLower & Environment.NewLine)
    46.             sw.Write("Password:" & txtCreatePassword.Text.ToLower & Environment.NewLine)
    47.             sw.Write("Question:" & cboPWquestion.SelectedItem.ToString & Environment.NewLine) 'SELECTED SECURITY QUESTION
    48.             sw.Write("Answer:" & txtPWAnswer.Text.ToLower & Environment.NewLine) 'ANSWER TO SECURITY QUESTION
    49.             sw.Close()        'CLOSE & DISPOSE OF STREAMWRITER
    50.             sw.Dispose()
    51.         Catch ex As Exception
    52.             MessageBox.Show(ex.Message & "ERROR PLACE 3")
    53.         End Try
    54.  
    55.         'ADD CUURENT USER SURNAME TO A LOG FILE OF SURNAMES:
    56.         'BEFORE ADDING, CHECK FOR DUPLICATE
    57.         Try
    58.             'FIRSTLY, READ EXISTING NAMES FROM LOG FILE
    59.             Dim srNew As New System.IO.StreamReader(Application.StartupPath & "\UserHistory.txt")
    60.             If srNew.Peek = -1 Then Exit Try 'Check if text file has text in it
    61.             Do While srNew.Peek <> -1
    62.                 arr.Add(srNew.ReadLine)
    63.             Loop
    64.             srNew.Close()
    65.             srNew.Dispose()
    66.             arr.Sort()
    67.         Catch ex As Exception
    68.             MessageBox.Show(ex.Message & "ERROR PLACE 4")
    69.         End Try
    70.  
    71.         Try   'NOW CHECK AGAINST TEXT ENTERED INTO SURNAME FIELD
    72.             For Each item As String In arr
    73.                 If txtSurname.Text.ToLower = item Then
    74.                     MessageBox.Show("Surname already exists.")
    75.                     Exit Try
    76.                 End If
    77.             Next
    78.             My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\UserHistory.txt", _
    79.           Environment.NewLine & txtSurname.Text.ToLower, True)
    80.         Catch ex As Exception
    81.             MessageBox.Show(ex.Message & "ERROR PLACE 5")
    82.         End Try
    83.  
    84.         MessageBox.Show("Congratulations! Account created successfully! You can now log on.", "Account Created", MessageBoxButtons.OK)
    85.         Me.grPersonal.Visible = False
    86.         Me.grpPassword.Visible = False
    87.         pnlLogin.Show()
    88.         Call FillUserHistory()
    Last edited by stimbo; Oct 5th, 2006 at 07:38 AM.

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