Question

I have a socket program in c#.I want to save the response of the server into textfile.Here is the code that i am using for it..

var streamReader = new StreamReader(client.GetStream());
var serverResponse = streamReader.ReadLine();

How to save this response in text file. Please help me..

Was it helpful?

Solution

using(var textFileWriter = new StreamWriter("textFile.txt"))
{
    var streamReader = new StreamReader(client.GetStream());
    var serverResponse = streamReader.ReadLine();

    textFileWriter.WriteLine(serverResponse);
}

This way you can save your stream into a file.

OTHER TIPS

you can use mentioned coe.

using(StreamWriter writer = new StreamWriter("debug.txt", true))
 {
   writer.WriteLine("whatever you text is");
 }

The second "true" parameter tells it to append.

http://msdn.microsoft.com/en-us/library/36b035cb.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top