Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm currently taking input from a registration form and download the input detail as a text file.
the resulted text file is: JimJone03/09/1998 00:00:00xxx@gmail.com 230436315

i want the resulted text file to be save as:

JimJone
03/09/1998
xxxx@gmail.com
230436315

any help on how can i assign it in this format

What I have tried:

[HttpPost]
public ActionResult Create(Information information)
{

var byteArray = Encoding.ASCII.GetBytes(information.FirstName + "" + information.Surname + "" + information.DOB + "" + information.Email + " " + information.Tel);
var stream = new MemoryStream(byteArray);
string lines = { byteArray };

return File(stream, "text/plain", "your_file_name.txt");



}
Posted
Updated 9-Dec-19 21:25pm
Comments
Richard MacCutchan 10-Dec-19 4:24am    
Why are you naming a string variable "byteArray"? Also, you are creating a single string of all items. You need to add newline characters to separate the different lines.

1 solution

try to use StreamWriter
var stream = new MemoryStream();
using (StreamWriter writer = new StreamWriter(stream))
{
    writer.WriteLine("__your text 1__");
    writer.WriteLine("__your text 2__");
}
return File(stream, "text/plain");
 
Share this answer
 
v2
Comments
Member 14677755 10-Dec-19 4:21am    
text 1
text 2
is taken from texboxes
Mehul M Thakkar 10-Dec-19 4:43am    
not a textbox but your object properties like
writer.WriteLine(information.FirstName + "" + information.Surname);
writer.WriteLine(information.DOB);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900