Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The code below puts the data "data123" into the file "data.txt" in the Server Path of the solution.

How do you retrieve the data in "data.txt" after you put it there?
C#
using (System.IO.FileStream fs = new System.IO.FileStream(Server.MapPath("~/data.txt"), System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read, 8, System.IO.FileOptions.None))
     {
         byte[] data = System.Text.Encoding.ASCII.GetBytes("data123");
         fs.Write(data, 0, data.Length);
         fs.Flush();
         fs.Close();
     }
Posted
Comments
Praveen Kumar Upadhyay 6-Jan-15 8:02am    
Question is not clear..
teledexterus 6-Jan-15 8:06am    
Filestream puts a file in the ServerPath. How do I retrieve the data from that file?
Tejas Vaishnav 7-Jan-15 1:44am    
can you please rate my solution.

1 solution

You can read file data using File.ReadAllLines like this...


C#
string[] lines = File.ReadAllLines(Server.MapPath("~/data.txt"));


File.ReadAllLines will return all the data(lines) written in that files.
 
Share this answer
 
v2

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