Hi all,

I was wondering if you can help me out with this. I have a dataGridView with a couple of books saved on it. When I click on a book, the book's story loads in a richTextBox. When I change that text and want to save it I want to save the content in a .txt file. How can I go about it?

I have included code for you to see what I want to do.

string FileLine = "";
StreamWriter OutputFile;

foreach (Book book in myBookList)
    //Book Book = new Book();
    Book nBook = myBookList[dgv.CurrentCell.RowIndex];

    OutputFile = new StreamWriter(nBook.TxtFileName);
    //I want it to be something like this:  {nBook.TxtFileName}.txt

    //Code to write data to file


Edited 2 Years Ago by Joemeister: Title change

What is the value of Book.TxtFileNameat present?

Just need to make sure it is a filepath ie C:\Desktop\nBook.txt and it should be fine to save as a .txt file

Edited 2 Years Ago by Mike Askew

I managed to get it working. The solution is quite simple.

line 10 should be: OutputFile = new StreamWriter(nBook.TxtFileName+".txt");

This question has already been answered. Start a new discussion instead.