I need to write the contents of a listbox to a textfile which then gets added as an attachment to an email. all of this works, but only once. if i try to send it, then edit the email address it sends to, then try to rewrite and send the file it gives me this error. "the process cannot access the file because it is being used by another process".

ReceiptWriter = IO.File.CreateText(filelocation)

            For i = 0 To Me.lstRecieptBox.Items.Count - 1


                Me.lstRecieptBox.SetSelected(i, True)

                ReceiptWriter.WriteLine(Me.lstRecieptBox.SelectedItem)

            Next
            ReceiptWriter.WriteLine("-------------------")
            ReceiptWriter.Close()


I want to be able to write the information to the file and then be able to edit the email address it sends to, and it be able to write over that file and send it again.

0 Answers