on 1 comment

Using StreamWriter To Write HTML File

Here, I will explain how to add textbox text into HTML file using StreamWriter.
First,we need to write the following code in aspx page.
Default.aspx
<div>
        <table border="1">
            <tr>
                <td>
                    <asp:Label ID="lbnname" runat="server" Text="Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lbnemail" runat="server" Text="Email"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="btnwrite" runat="server" Text="Write" 
                        onclick="btnwrite_Click" />
                </td>
                <td>                    
                    <asp:Button ID="btnreset" runat="server" Text="Reset" 
                        onclick="btnreset_Click" />
                </td>
            </tr>         
        </table>
    </div>
Now, first we add namespace System.IO  in Default.aspx.cs  page  and also add html file  from addNewItem  and give "name nam_email.htm".
 Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnwrite_Click(object sender, EventArgs e)
    {       
        int id = 0,;   
        StreamWriter sw = new StreamWriter(Request.PhysicalApplicationPath + "nam_email.htm", true);      
       sw.WriteLine("<tr><td>" + id +"</td><td>" + txtname.Text + "</td><td>" + txtemail.Text + "</td></tr>");        
        sw.Close();
    }  
    protected void btnreset_Click(object sender, EventArgs e)
    {
        txtname.Text = string.Empty;
        txtemail.Text = string.Empty;
    } 
}
on Leave a Comment

What is .NET Framework?

.NET Framework is a complete environment that allows developers to develop, run, and deploy the following applications:
  • Console applications
  • Windows Forms applications
  • Windows Presentation Foundation (WPF) applications
  • Web applications (ASP.NET applications)
  • Web services
  • Windows services
  • Service-oriented applications using Windows Communication Foundation (WCF)
  • Workflow-enabled applications using Windows Workflow Foundation (WF)
on Leave a Comment

What is ASP.NET?

ASP.NET is a specification developed by Microsoft to create dynamic Web applications, Web sites, and Web services. It is a part of .NET Framework. You can create ASP.NET applications in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The ASP.NET compiles the Web pages and provides much better performance than scripting languages, such as VBScript. The Web Forms support to create powerful forms-based Web pages. You can use ASP.NET Web server controls to create interactive Web applications. With the help of Web server controls, you can easily create a Web application.
aspdotnet-learn. Powered by Blogger.