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


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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.