Closed Thread
Results 1 to 7 of 7

Thread: Open File text into Textbox

  1. #1
    Psynic's Avatar
    Psynic is offline Learning Programmer
    Join Date
    May 2009
    Location
    Canada, AB
    Posts
    61
    Blog Entries
    1
    Rep Power
    11

    Open File text into Textbox

    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;
                    }
                    
                }
            }

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: Open File text into Textbox

    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.

  4. #3
    Psynic's Avatar
    Psynic is offline Learning Programmer
    Join Date
    May 2009
    Location
    Canada, AB
    Posts
    61
    Blog Entries
    1
    Rep Power
    11

    Re: Open File text into Textbox

    Yess thanks game maker savin my butt once again do you happen to know how i could get my textbox to scale with the window if its maximized?

  5. #4
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: Open File text into Textbox

    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.

  6. #5
    Psynic's Avatar
    Psynic is offline Learning Programmer
    Join Date
    May 2009
    Location
    Canada, AB
    Posts
    61
    Blog Entries
    1
    Rep Power
    11

    Re: Open File text into Textbox

    thanks a ton that helped with my scrollbars too if only i could +rep you 4 times in a day.

  7. #6
    Join Date
    Nov 2009
    Location
    I seem to be lost...
    Posts
    1,566
    Blog Entries
    1
    Rep Power
    22

    Re: Open File text into Textbox

    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.

  8. #7
    lobo521 is offline Learning Programmer
    Join Date
    Jan 2010
    Posts
    57
    Rep Power
    8

    Re: Open File text into Textbox

    again use "using" keyword. This frees resources even if exception occurs.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Help]Open Text File And Excute Certain Commnad
    By av01d3r in forum C and C++
    Replies: 3
    Last Post: 07-11-2011, 02:05 AM
  2. Batch file to open multiple text files at once using Notepad
    By terrylau in forum General Programming
    Replies: 3
    Last Post: 07-06-2009, 12:23 AM
  3. Backup current text in textbox after x amount of time
    By Grue in forum Visual Basic Programming
    Replies: 4
    Last Post: 06-11-2009, 09:29 AM
  4. Detecting text change of readonly textbox without postback
    By engr in forum ASP, ASP.NET and Coldfusion
    Replies: 3
    Last Post: 02-03-2009, 10:46 AM
  5. Save textbox to txt, html, php etc. file
    By Logan in forum Visual Basic Programming
    Replies: 2
    Last Post: 01-26-2009, 05:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts