c# example - stringbuilder to file
stringbuilder-to-file.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
StringBuilder stringb = new StringBuilder();
stringb.Append("Eclectus Parrot.");
stringb.AppendLine();
stringb.Append("Hyacinth Macaw.");
stringb.AppendLine();
stringb.Append("Vulturine Parrot.");
stringb.AppendLine();
stringb.Append("Cuban Amazon.");
Label1.Text = stringb.ToString();
string appPath = Request.PhysicalApplicationPath;
string filePath = appPath + "stringbuilderoutput.txt";
//this code section write stringbuilder content to physical text file.
using (StreamWriter swriter = new StreamWriter(filePath))
{
swriter.Write(stringb.ToString());
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - stringbuilder to file</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - stringbuilder to file
</h2>
<hr width="550" align="left" color="Gainsboro" />
<br />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="stringbuilder to file"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to get the length of a StringBuilder
- How to check if StringBuilder contains a substring
- How to find a substring in a StringBuilder
- How to apply regex replace on a StringBuilder
- How to get a comma separated list from a StringBuilder
- How to write a StringBuilder data to a CSV file
- How to check if a StringBuilder is empty
- How to determine if two StringBuilders are equals
- How to convert a StringBuilder to a byte array
- How to convert a StringBuilder to a string array