I have the webpage in application server which have the links of media files on medai server.
When I click on these links the media file is playing and not downloading.
And I want to download it.
If the application and media was on one server then its easy to use WriteFile method but in that case we can't use this method.
Can any one have idea?
Hi,
Based on my understanding, you want to download the file from another server. If I have misunderstood you, please feel free to let me know.
If we want to download the file that is in another server instead of opening it directly, we can use the HttpWebRequest and HttpWebResponse to request it and write it to the client.
For example:
//Use your url. HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create("http://www.test.com/test/test.mp3"); HttpWebResponse resp = (HttpWebResponse)webrequest.GetResponse(); byte[] btFile = new byte[resp.ContentLength]; resp.GetResponseStream().Read(btFile, 0, Convert.ToInt32(resp.ContentLength)); Response.AddHeader("Content-disposition", "attachment; filename=" + "test.mp3"); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(btFile); Response.End();
I hope this helps.
0 comments:
Post a Comment