CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2011
    Posts
    59

    Extra data from textBox. Please help.

    Hello, and thank you.

    I am trying to read in user defined input from a text box and use that input as a txt file name.

    The problem I am having is when I read the text "test" in I am getting

    "System.Windows.Forms.TextBox, Text: test"

    When I try and write the file test.txt I get the exception "The given path's format is not supported."

    The code:

    string profileName1 = "C:\\";
    char [] profileName2 = new char[profileNameBox.TextLength];
    string placeHolder = profileNameBox.ToString();


    try
    {
    StreamWriter writer;
    writer = File.CreateText(profileName1 += placeHolder += ".txt");
    writer.WriteLine("This works");
    writer.Close();
    Console.WriteLine("TXT file Created");
    }
    catch (Exception ex)
    {
    MessageBox.Show("Exception: " + ex.Message);
    }

    So Id like to know how I can get ONLY the text value into my variable with out the extra system notation. Thank you.

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: Extra data from textBox. Please help.

    In the definition of string placeholder, try changin' the ".ToString" to ".Text". I think what you are doing is converting the control to a string, rather than acquiring the text in the text box.

  3. #3
    Join Date
    Mar 2011
    Posts
    59

    Re: Extra data from textBox. Please help.

    Thank you that is exactly what I was in need of.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured