0

I am receiving an HttpWebResponse containing both XML and a FileStream of unknown length. I know that streams can contain a very large amount of bytes, but the upper limits of strings are significantly smaller. Inside the XML I have a <size> tag that tells me how big the FileStream is.

Is it possible to get the information from the <size> prior to assigning the stream contents to a string? I want to prevent unhandled exceptions when I myXMLresponse=myStream.ReadToEnd, if the service sends me something bigger than it should.

Community
  • 1
  • 1
CWilson
  • 425
  • 10
  • 28
  • You could certain just read some of the bytes, like with `ReadLine` before reading the rest of the stream. – Peter Ritchie Jan 20 '17 at 20:25
  • @PeterRitchie I like your idea: instead of examining *before* assigning to a string, examine *while* assigning to string, examining one line at a time. – CWilson Jan 23 '17 at 20:52

0 Answers0