I have a winform with two data grids and several text boxes. I want to give the user the option of exporting this data to my drive in a text document instead of my choice. I also want the text document to be pre-formatted, and to plug in the values of text boxes and datagrids.
Is it possible to pre-format a txt document using StreamWriter? And how does the user know about giving an option to save this export file?
You have to format the string that you want to write through the stream. Using
(stream w = new streamer (file path) {string firstLine = string.Concat ("\ n", string.format (@ "Customer number: {0}, customer Name: {1} ", text box 1. text, text box 2. text)); String second lines = string Format (@ "address: {0}", textbox 3. text); Sw.WriteLine (FIRSTLINE); Sw.WriteLine (secondLine); // Loop through your DataGrid view Line or cell and do the same as sw.Flush (); Sw.Close (); }
Output to file
Customer's number: [12345678] Customer name: [Customer's name]
Address: [Address]
Where information between the square brackets is inputed by the user through the text boxes.
Comments
Post a Comment