Tuesday, May 06, 2008

Generating Ms Word document in ASP.NET and C#

It is very frequntly asked question in any of the forum or question-answer section on websites. So I decided to write a very compact article with source code.

It is as simple as 123.

Lets start with creating a simple .aspx page where we will give a text box to enter user's Name and a button to click on. After clicking on the button Ms Word document will be generated.
.aspx page
The code will be


<form id="form1" runat="server">
<div>
Write your name: <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator id="req1" runat="server" ControlToValidate="txtName" Text="*"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="btn" runat="server" OnClick="GenerateMsWordDoc" Text="Generate Ms Word Document" />
</div>
</form>


For complete article, visit http://www.dotnetfunda.com/articles/article9.aspx

No comments: