3

I want to write Argotic to memorystream and then return it as a string to another function. and this is what I've written :

            Stream st = new MemoryStream();
            Feed.Save(st); //argotic Save method has the ability to write into Stream
            StreamReader sr = new StreamReader(st);
            return sr.ReadToEnd();

but I only got an empty string although the st.length shows me the correct length but there no character in it :-?

how Can I solve this problem?

regards.

ba__friend
  • 5,783
  • 2
  • 27
  • 20
Vahid Hashemi
  • 5,182
  • 10
  • 58
  • 88
  • When working with streams you should get familiar with the `using` statement. http://msdn.microsoft.com/en-us/library/yh598w02.aspx – ba__friend Jun 26 '11 at 10:09
  • I'm totally familiar with how to use "using" the above snippet is for the sake of giving an example. – Vahid Hashemi Jun 26 '11 at 10:33

1 Answers1

4

Reset the position of the stream to 0 to read from the beginning, after the save. Otherwise you'll read from the current position, which is the end of the stream since it has just been written to:

st.Position = 0;
Julien Lebosquain
  • 40,639
  • 8
  • 105
  • 117
  • thanks for your answer I've changed my code to something like : int i = st.Read(b, 0, (int)st.Length); and then convert byte to string and now its working :) – Vahid Hashemi Jun 26 '11 at 10:34