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.
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:
0 comments:
Post a Comment
thanks for your comment!