![]() ![]() Sfd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" įile.WriteAllText(sfd.FileName, textBox_ListDestination. private void button1_Click(object sender, EventArgs e) ![]() This may help with the system hanging, and some debugging. If you are hitting the code multiple times during debugging, my only suggestion would be to wrap the SaveFileDialog in a 'using' statement. If you would like an example on how to work with a file using OpenFile, there should be a couple of examples on the internet, but based on your need, I think File.WriteAllText will work. Here is an example: (v=VS.71).aspx Note how the example closes the file, if you wanted to do working in the file, you would code that work before the CloseFile method is called. If you want to work with your file using OpenFile, then you will have to change how you work with the file. In your code, when File.WriteAllText is executed, it blows up because the file is already in use. When you call OpenFile, you are placing a lock on that file. When you call File.WriteAllText, it opens, writes and closes the file for you automatically. If I were to guess, you may be having problems with memory allocation (working with unmanaged resources) coupled with multiple attempts at debugging, and maybe re-saving to the same file over and over may have left a bad file pointer. I don't have any issues when I try to recreate the problem using your first example code. If ((myStream = saveFileDialog1.OpenFile()) != null) If (saveFileDialog1.ShowDialog() = DialogResult.OK)įile.WriteAllText(saveFileDialog1.FileName, textBox_ListDestination.Text) Īnd private void button_SaveToFile_Click(object sender, EventArgs e) SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" Solution I suppose you have to export the C array list into the text file. You would like to save it into a text file. It requires data in a simpliest possible format: valuex1 valuey1 valuex2 valuey2. ![]() SaveFileDialog saveFileDialog1 = new SaveFileDialog() Saving C List Into Text File Tomasz Borawski 54.8 k 0 8 Introduction Let say you have got a C list of objects. How to export data to a plain text file Ask Question Asked 9 years, 2 months ago Modified 8 years, 2 months ago Viewed 29k times 9 I am preparing data used by a command line program. Here are the code sections that I have tried, but both create the same hang: private void button_SaveToFile_Click(object sender, EventArgs e) The only way out of it is to click the "stop-debugging" button. The program seems to work fine up until the save dialog, and I don't get any errors, but once I click the save button the application just hangs. I am trying to add a SaveFileDialog to my Windows Application, in which I save a simple text file from the contents of a multi-line text box. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |