Download file to local file system

  • Thread starter Thread starter Stefan Nuxoll
  • Start date Start date
S

Stefan Nuxoll

I am working on a player application for my podcast, currently all it
does is make a Windows Media Player control open the MP3 file you select
from a listbox populated by the RSS feed. I am trying to add a 'save'
feature that downloads the MP3 to the local file system, but everything
I have tried has resulted in corrupt files. Can anyone help?
 
Stefan,

Can you show your code, what you have already? It would help serve as a
base.
 
Nicholas said:
Stefan,

Can you show your code, what you have already? It would help serve as a
base.
I kind of deleted all of my code in anger, but basically it opened a
save dialog, instanced a webclient, read the file line by line and
copied it into a stream at the location the user choose in the save
dialog. I am guessing reading the file in the fashion I am doing is the
issue?
 
Yep, since it's a binary file you want to read and write the file in
bytes instead of line by line. Otherwise it will read in "lines" that
may or may not exist, and when it's writing those lines it will remove
whatever character it deems is a line break and replace it with the
current environment's line break thus corrupting the file.
 
How would you suggest doing this than, do I still have to go the stream
approach or is there some magic, copy from URL to local filesystem
command?
 
This should do it:

WebClient Client = new WebClient();

try

{

Client.DownloadFile(RemoteFileUrl, LocalFileName);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top