Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a file from StreamReader stream

Tags:

Im currently trying to downlaod a audio track from a WCF, i need some help writing it to the harddisk, how do i configure streamwriter or other to do this in a webApp?

// Use Service to download stream (returns System.IO.Stream)  Stream stream = MyService.Download(("1231")); // ReadStream StreamReader reader = new StreamReader(stream); reader.ReadToEnd();  // Write this stream to a file/Hard disk ??? 
like image 509
RY4N Avatar asked Mar 22 '12 11:03

RY4N


People also ask

Can be used to write a stream of text to a file?

C# StreamWriter The StreamWriter class in C# is used for writing characters to a stream. It uses the TextWriter class as a base class and provides the overload methods for writing data into a file. The StreamWriter is mainly used for writing multiple characters of data into a file.

How does StreamReader work in C#?

C# StreamReader is used to read characters to a stream in a specified encoding. StreamReader. Read method reads the next character or next set of characters from the input stream. StreamReader is inherited from TextReader that provides methods to read a character, block, line, or all content.

What is a StreamReader?

StreamReader is designed for character input in a particular encoding, whereas the Stream class is designed for byte input and output. Use StreamReader for reading lines of information from a standard text file. Important. This type implements the IDisposable interface.


1 Answers

Stream stream = MyService.Download(("1231")); using (Stream s = File.Create(path)) {     stream.CopyTo(s); } 
like image 171
L.B Avatar answered Nov 10 '22 11:11

L.B