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.
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.
Re: Extra data from textBox. Please help.
Thank you that is exactly what I was in need of.