none
StreamWriter and FileStream RRS feed

  • Question

  •  

    Good morning.

     

    I have a questoin regarding appending an open file.

     

    As an example situation:

     

    Lets say I write the values "A", "B", "C", "D" to a file name myFile.

     

    Lets assume I used a WriteLine instead of a Write so a vbCrLf would be included after each Letter

     

    When we open the file it looks like this:

     

    "A"

    "B"

    "C"

    "D"

     

    Within my application, I read in these values into an ArrayList and display them into a combo box.

     

    If the user selects a value in the combobox and chooses to Delete it from the file, I want to remove it from the ArrayList and the File with out having to first truncate the file.

     

    Currently I am truncating the file -- removing the value from the ArrayList and then rewriting the file with the new values in the array list.

     

    As an example:

     

    User decides to delete "C"

     

    I truncate the file, myFile, I then remove the "C" value from the ArrayList, and then write the ArrayList contents back to , myFile.

     

    myFile is now:

     

    "A"

    "B"

    "D"

     

    Is there a way to do this without first truncating the file?

     

    Thanks

     

    - Brad

    Friday, February 15, 2008 2:40 PM

Answers

All replies

  •  

    You might want to take a look at:

     

     

    File.WriteAllLines()

    Friday, February 15, 2008 3:46 PM
  •  

    Thanks!

     

    I think your on the right track and this is going to help.

     

    I found information on the File.WriteAllLines() but I am struggling to find how to use it with an arraylist.

     

    I found how you can use it with an array, would the arraylist be the same?

    Friday, February 15, 2008 4:59 PM
  • Hi,

     

    If you can do it with an array then one might convert the array list via myArrayList.ToArray()

     

    Friday, February 15, 2008 5:02 PM