Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have a one multilined text box.i want to save that text as a word file(.docx) using save dialog box.

Thanks in advance.
Posted
Updated 17-Jan-12 22:57pm
v2

hai shrivastava,

create a word file(.docx) dynamically in runtime and add text as textbox content in coding ..

refer this
=============
http://support.microsoft.com/kb/316384

http://msdn.microsoft.com/en-us/library/aa192483(v=office.11).aspx
 
Share this answer
 
Comments
Richard MacCutchan 18-Jan-12 5:29am    
Your explanation is difficult to understand and your links are both broken.
You cannot save a text file as a word document through a save dialog[^]. The dialog merely allows your user to decide the location and name of the file that your content will be saved in. You must still convert the content into the correct format and then write it into the file selected. Take a look at the Word Interop[^] library for information on creating doc/docx files.
 
Share this answer
 
ASP.NET
<asp:textbox id="txtDescription" runat="server" textmode="MultiLine" height="100" xmlns:asp="#unknown">
            Width="280"></asp:textbox>
        <asp:linkbutton id="lb_Download" runat="server" text="Download file" onclick="lb_Download_Click" xmlns:asp="#unknown"></asp:linkbutton>



C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtDescription.Text = "lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
        }
    }
    protected void lb_Download_Click(object sender, EventArgs e)
    {
        string strContents = null;
        strContents = txtDescription.Text;

        string attachment = "attachment; filename=test.doc";
        Response.ClearContent();
        Response.ContentType = "application/doc";
        Response.AddHeader("content-disposition", attachment);
        Response.Write(strContents);
        Response.End();
    }
 
Share this answer
 
Comments
mayankshrivastava 18-Jan-12 6:11am    
Dear mukund,
Thanks for reply but i want to save a file using save file dialog box.
C#
object missing = System.Reflection.Missing.Value;
       object Visible = true;
       object start1 = 0;
       object end1 = 0;

       Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
       Microsoft.Office.Interop.Word.Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
       Microsoft.Office.Interop.Word.Range rng = adoc.Range(ref start1, ref missing);
       SaveFileDialog saveFileDialog1 = new SaveFileDialog();
       saveFileDialog1.InitialDirectory = @"C:\";
       saveFileDialog1.Title = "Save word Files";
       saveFileDialog1.CheckFileExists = false;
       saveFileDialog1.CheckPathExists = true;
       saveFileDialog1.DefaultExt = "docx";
       saveFileDialog1.Filter = "Docx files (*.docx)|*.doc|All files (*.*)|*.*";
       saveFileDialog1.FilterIndex = 2;
       saveFileDialog1.OverwritePrompt = true;
       saveFileDialog1.RestoreDirectory = true;

       if (saveFileDialog1.ShowDialog() == DialogResult.OK)
       {
           rng.Font.Name = "Calibri (Body)";
           rng.InsertAfter(txtenglishtext.Text);
           object filename = saveFileDialog1.FileName;
           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;
       }
 
Share this answer
 
v2

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