Click here to Skip to main content
15,914,160 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Could you please tell me, In asp.net how to enter data into MS-word custom fields

which i entered in a text box. i did this in vb.net deski top application , is it

possible in asp.net application. Plese suggest me some code to write data.
Posted
Updated 19-Apr-11 2:31am
v3

C#
protected void GenerateMsWordDoc(object sender, EventArgs e)
    {
        string strBody = "<html>" +
            "<body>" +
                "<div>Your name is: <b>" + txtName.Text + "</b></div>" +
                "<table width="100%" style="background-color:#cfcfcf;"><tr><td>1st Cell body data</td><td>2nd cell body data</td></tr></table>" +
                "Ms Word document generated successfully." +
            "</body>" +
            "</html>";
        string fileName = "MsWordSample.doc";
        // You can add whatever you want to add as the HTML and it will be generated as Ms Word docs
        Response.AppendHeader("Content-Type", "application/msword");
        Response.AppendHeader ("Content-disposition", "attachment; filename="+ fileName);
        Response.Write(strBody);
    }


Edit - Removed the extra PRE tag. -Ankur
 
Share this answer
 
v2
Comments
jagadeesh kumar adabala 27-May-11 7:30am    
Hi, thnx for this code, but, i think we cannot insert any custom fields through this code.
jagadeesh kumar adabala 28-May-11 1:32am    
we can generatea word document using this, but how to insert customfields
^(([0-1]{1}[0-9]{1}|2[0-3]):([0-5]{1}[0-9]{1}|60)|24:00)$
 
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