I have 6 Text boxes and i want to append the textboxes entered text to a csv file but it throws error : Input string was not in a correct format.
below is the code can any one rewrite the working code
String filePath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.FullName,"fetching.csv");
String strSeperator=",";
StringBuilder sbOutput = new StringBuilder();
int env = Convert.ToInt32(textBox1.Text); //error is throwing from this line
int user = Convert.ToInt32(textBox2.Text);//error is throwing from this line
int pass = Convert.ToInt32(textBox3.Text);//error is throwing from this line
int host = Convert.ToInt32(textBox4.Text);//error is throwing from this line
int port = Convert.ToInt32(textBox5.Text);//error is throwing from this line
int service = Convert.ToInt32(textBox6.Text);//error is throwing from this line
int[][] inaOutput = new int[][]{new int[]{env,user,pass,host,port,service}};
int ilength = inaOutput.GetLength(0);
for(int i=0;i<ilength;i++)
sbOutput.AppendLine(String.Join(strSeperator,inaOutput[i]));
File.AppendAllText(filePath,sbOutput.ToString());
userandhostcan be integers? Those looks like strings. But, since you're writing to a file, they're all string in the end. Don't use this:Directory.GetCurrentDirectory()to get the path to you executable. UseApplication.StartupPath.