Oct 20, 2015

Posted in , , , ,

How to Produce Text file in ASP.NET 4.6?

In this example we explain that how to produce text file in ASP.NET 4.6 or write data to the text file fetching from the database.

How to Produce Text file in ASP.NET 4.6?


Here usually we create new file and write data to text file from the database.below is code for creating text file and write data to it.

HostForLIFE.eu

fs1 = new FileStream(Server.MapPath("Files\\demo.txt"), FileMode.OpenOrCreate, FileAccess.Write);

writer.Write("Name :" + Convert.ToString(dtDetails.Rows[0]["name"]) + Environment.NewLine);
    writer.Write("City :" + Convert.ToString(dtDetails.Rows[0]["Clty"]) + Environment.NewLine);
    writer.Write("Country" + Convert.ToString(dtDetails.Rows[0]["Country"]) + Environment.NewLine);
writer.Close();

you can also overwrite the existing file if exist like just write
fs1 = new FileStream(Server.MapPath("Files\\demo.txt"), FileMode.Create);

And here is the output:
How to Produce Text file in ASP.NET 4.6?

0 comments:

Post a Comment

thanks for your comment!