Hi riyab,
Refer the below sample.
HTML
<div>
<% Html.BeginForm("Index", "Home", FormMethod.Post); %>
<input type="text" name="text" id="txtText" />
<input type="submit" value="Upload" />
</div>
Controller
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string text)
{
string path = Server.MapPath("~/Files/test.txt");
using (StreamWriter sw = System.IO.File.CreateText(path))
{
sw.WriteLine(text);
}
return View();
}
Which will ctreate a txt file with the name test inside project Files folder with the TextBox value.