File Read/Saving Question.

Is it possible to open a file and insert a string to the end of it without having to read the data then resave it all



Answer this question

File Read/Saving Question.

  • Andy Rock

    Yes

    My.Computer.Filesystem.WriteAllText(<FileName>,<Content>, <Append>)

    so

    My.Computer.Filesystem.WriteAllText("C:\test.txt", "xyz", True)

    will append xyz to the end of the contents of c:\test.txt


  • jeffo

    Does it give an error or anything - what type of project are you working on.

    You need to be more specific.

    If th file doesnt exist it will create it. If you've got a path wrong and no error handling then thats just bad coding.

    The command works just fine for VB2005/Express and does exactly what you asking.

    Have you tried a very simple application with this command in which does only this. Did that work or fail


  • Tobias Larsson Hult

    That line of code makes VB crash when you actually open the project or when you run it If it happens when you run it, it might be because you don't have either the path to the test file correct, or the file doesn't exist. Post what code you have written that is causing this.

    james

    aka:Trucker


  • James D. Wright

    Everytime i add this it makes vs2005 crash every time i open the project.


  • File Read/Saving Question.