Pergunta

I'm a newbie and I'm developing a windows application. I need to download a video file from my site and that's my issue here. I had designed a custom down-loader, through which I can download images, text files from my site. But I wasn't able download videos from my site. Could anyone please help me out..?

WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(new Uri("http://mysitename.com/Videos/vid.mp4"), "c:\\movie.mp4");

I don't want to download by means of response content dispatch because my client wants me to download through custom browser.. so please let me know solutions from you experts.. thank you

Foi útil?

Solução

I have tried to download a video file with WebClient and it works. My setup is as below:

I have a virtualdirectory(Video) in defaultwebsite (IIS) which has this video file.

I just use the below code to download the video file to C drive:

var client = new WebClient();
Uri address = new Uri("http://localhost/Video/wildlife.wmv");
client.DownloadFileAsync(address, @"c:\video.wmv");

Also note since you are downloading in Async fashion, wait for about a min for the operation to complete for the full file to be downloaded. Initially it shows 0 bytes but based on the size it takes some time to complete it.

UPDATE: If your server doesnt have the file mime type specified then just add to the collection of mime types that IIS can serve and you can download the file without any problem.

When adding MIME type the following values to be used are (for your scenario):

File Extension: .mp4
MIME Type: video/mp4 

To add mime types in IIS follow these links:

  1. For IIS 4,5
  2. For IIS 6
  3. For IIS 7

Outras dicas

This sounds more like a server issue, but if you are doubting your code, you may want to try download sync (I have had some issues in the past downloading async). Another way is to use the WebRequest class. If this server is very remote, try pinging beforehand. I think that you should also check to make sure the file is on the server, and if the file is really big, you should check to see if the file finished uploading.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top