Hi nauna,
Check this example. Now please take its reference and correct your code.
Code
C#
protected void OnSave(object sender, EventArgs e)
{
string folderPath = Server.MapPath("~/Uploads");
if (!System.IO.Directory.Exists(folderPath))
{
System.IO.Directory.CreateDirectory(folderPath);
}
string text = "Name: Bharat";
text += "\n";
text += "Country: India";
using (System.IO.StreamWriter sw = System.IO.File.CreateText(folderPath + "/Text.txt"))
{
sw.WriteLine(text);
sw.Close();
}
}
VB.Net
Protected Sub OnSave(ByVal sender As Object, ByVal e As EventArgs)
Dim folderPath As String = Server.MapPath("~/Uploads")
If Not System.IO.Directory.Exists(folderPath) Then
System.IO.Directory.CreateDirectory(folderPath)
End If
Dim text As String = "Name: Bharat"
text += vbLf
text += "Country: India"
Using sw As IO.StreamWriter = IO.File.CreateText(folderPath & "/Text.txt")
sw.WriteLine(text)
sw.Close()
End Using
End Sub