Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have a multilined text box. i am writing some text in a text box then when i am clicking on button event then i want to save these text as a word file(2003,2007,etc) in a selected path in my lappy.
Posted
Updated 6-Jan-12 22:35pm
v2

Dear shrivastava,

private void button1_Click(object sender, EventArgs e)
      {
          object missing = System.Reflection.Missing.Value;
          object Visible=true;
          object start1 = 0;
          object end1 = 0;

          ApplicationClass WordApp = new ApplicationClass();
          Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
          Range rng = adoc.Range(ref start1, ref missing);

          try
          {
              rng.Font.Name = "Georgia";
         rng.InsertAfter("Hello World!");       // put your text box text here
              object filename = @"D:\MyWord.doc";
              adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
              ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
              WordApp.Visible = true;
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }


For better understanding check this link
http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/[^]

More about it
Microsoft Word Documents from ASP.NET[^]

File Save(Check this link for better understanding)
http://www.c-sharpcorner.com/uploadfile/mahesh/savefiledialog-in-C-Sharp/[^]

Thanks
 
Share this answer
 
v6
Comments
mayankshrivastava 7-Jan-12 4:57am    
thanks for code sridhar it works.
but when i am clicking a button event i want's "save as file" dialog box. then i save a word file in my location .
Sridhar Patnayak 7-Jan-12 5:05am    
Check the edited solution for file save link.
mayankshrivastava 7-Jan-12 6:13am    
thanks for reply sridhar..
when i am saving the new file it gives me message -
file c:\newfile.docx does not exist.verify that the correct file name was given.
Import namespace using System.IO;
TextWriter tw = new StreamWriter(@"C:\Hello.doc");
tw.WriteLine(Textbox1.Text);
tw.Close();
 
Share this answer
 
Comments
mayankshrivastava 7-Jan-12 5:03am    
Dear supriya,i got the code for save the file but i want to save a file from "save as" diaolog box.

and thank's for reply.

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