String to file
string-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)
{
string stringOfBirds = "Northern Lapwing, Masked Lapwing, Ringed Plover, Wrybill";
Label1.Text = "string of birds............<br />";
Label1.Text += stringOfBirds;
string appPath = Request.PhysicalApplicationPath;
string filePath = appPath + "birds.txt";
//string to physical text (.txt) file
using (StreamWriter swriter = new StreamWriter(filePath))
{
swriter.Write(stringOfBirds.ToString());
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# example - string to file</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
c# example - string to file
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
Text="string to file"
OnClick="Button1_Click"
Height="40"
Font-Bold="true"
/>
</div>
</form>
</body>
</html>
- How to replace a substring of a string
- How to split a string with specific delimiter to populate an array
- How to compare two strings by ignoring case
- How to escape brackets in a formatted string
- How to convert a string to a float array
- How to convert a string to a guid
- How to convert a string to a generic list
- How to convert a string to an IP address
- How to convert a string to an int array
- How to split a string to key value pairs