I am tryin to open a file's text into my textbox for my notepad project. this code works until
StreamReader sr = new StreamReader(fs, System.Text.Encoding.ASCII);
Where it says the stream is unreadable. can anyone shed some light on this situation? +rep thanks to all for the help.
Code:private void fileToolStripMenuItem1_Click(object sender, EventArgs e) { OpenFileDialog opDialog = new OpenFileDialog(); opDialog.Title = "Specify File To Open.."; opDialog.Filter = "Any Type(*.*)\"|*.*"; if (opDialog.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(opDialog.FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); StreamReader sr = new StreamReader(fs, System.Text.Encoding.ASCII); if (opDialog.ShowDialog() == DialogResult.OK) { richTextBox1.Text = opDialog.FileName; } } }
This will open a file.Code:openFile.FileName = ""; openFile.Title = "Open A Text Document."; openFile.Filter = "(*.txt)|*.txt|(*.etf)|*.etf"; DialogResult result = openFile.ShowDialog(); if (result == DialogResult.OK) { //Reokads the text file System.IO.StreamReader OpenFile = new System.IO.StreamReader(openFile.FileName); //Displays the text file in the textBox textBox.Text = OpenFile.ReadToEnd(); //Closes the proccess OpenFile.Close(); }
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
Yess thanks game maker savin my butt once againdo you happen to know how i could get my textbox to scale with the window if its maximized?
Ya all you need to do is go into properties(of the textbox) and find the dock properties and set it to the center dock and it will size with the form.![]()
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
thanks a ton that helped with my scrollbars tooif only i could +rep you 4 times in a day.
no prob., that would be sweet.
![]()
Knowledge: Intermediate C#, Beginner AS3, HTML, CSS, Binary, Hex, Octal.
Science is only an educated theory, which we cannot disprove.
again use "using" keyword. This frees resources even if exception occurs.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks