Connecting Tech Pros Worldwide Forums | Help | Site Map

Saving files locally downloaded from the net

Xarky
Guest
 
Posts: n/a
#1: Nov 16 '05
Hi,
I am downloading data from the Internet using the following lines.

networkStream = tcpClient.GetStream(); // tcpClient specifies port +
ip
StreamReader streamReader = new StreamReader(networkStream);
response = streamReader.ReadLine();

After doing correct parsing of the downloaded code, I identify the
file extension such as txt, jpg, mp3, etc.

Now I would like to write the file locally, by creating the file and
storing the data retrieved. To write to the file I am using the
following.

StreamWriter streamWriter = new StreamWriter(path, false);
streamWriter.Writeline(data);

This technique has worked for text documents but is failing in other
files.

Can someone provide some help.
Thanks in Advance

Morten Wennevik
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Saving files locally downloaded from the net


Hi Xarky,

I believe the problem may be caused by reading single lines which doesn't
make sense for non text data.
I would use StreamReader.ReadToEnd, WebClient.DownloadFile or handle the
Stream directly and reading chunks of bytes.

--
Happy Coding!
Morten Wennevik [C# MVP]
Closed Thread


Similar C# / C Sharp bytes