Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How do i print the text box and labels in a form to a doc or text file using code
without writing 1000 lines of code

IN .NET LANGUAGE

Note:The solution 1 posted below is not for .Net u will have to make little changes. eg dim while declaration of variables
Posted
Updated 9-May-13 6:25am
v4
Comments
ZurdoDev 9-May-13 8:05am    
To text is very easy, use File.WriteAllText(). If you mean Microsoft Word for doc then use the Office Interop dll.
Polarfuze 9-May-13 11:55am    
how do i concatenate in this format filetext="Name is "+label1.text +" age is "+label2.text + " "
the lines in the string do appear in the file but not the contents of the label.text
ZurdoDev 9-May-13 11:58am    
Is this VB? Use & instead of + or use a StringBuilder if there is a lot of text.
Polarfuze 9-May-13 12:15pm    
Thank you the code is working now
ZurdoDev 9-May-13 12:17pm    
Good to hear.

To text is very easy, use File.WriteAllText(). In VB, use & for concatenating or use a StringBuilder.
 
Share this answer
 
Hello!

I'll say you for .txt files (text files). I brlive for .doc is the same.

C#
string fromLabel;
string fromTB;
string Path = @"C:\Users\Administrator\"; //Write the path here

void FileWrite(string TextHere, string path)
{
   string line = TextHere;
   System.IO.StreamWriter file = new System.IO.StreamWriter(path);
   file.WriteLine(line);
   file.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
   fromTB = textBox1.Text;
}

private void button1_Click(object sender, EventArgs e)
{
   //Save button
   FileWrite(fromTB, Path);
   FileWrite(fromLabel, Path);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900