Asked by:
error ( is not a valid virtual path )

Question
-
User1456523893 posted
i use this code to download MP4 file
Protected Sub Button1_Click1(sender As Object, e As EventArgs)
Response.ContentType = "application/mp4"
Response.AppendHeader("Content-Disposition", "attachment; filename=testing.mp4")
Response.TransmitFile("Money.Heist.S01E10.mp4")Response.End()
End Sub
when i change Response.TransmitFile("Money.Heist.S01E10.mp4") to https link erroe ( is not a valid virtual path )
Protected Sub Button1_Click1(sender As Object, e As EventArgs)
Response.ContentType = "application/mp4"
Response.AppendHeader("Content-Disposition", "attachment; filename=testing.mp4")
Response.TransmitFile("https://domainname.com/movies/Money.Heist.S01E10.mp4")Response.End()
End Sub
Tuesday, September 18, 2018 8:19 AM
All replies
-
User-821857111 posted
The TransmitFile method needs a virtual file path, not a URL. If the file is located on your server, you need to pass in the file path. If you want to return files that are not located on your server, you can't use TransmitFile with a URL. You can redirect the user to the other location or obtain the file and then serve it.
Tuesday, September 18, 2018 9:00 AM -
User1456523893 posted
thanks Mr. Mike
i have a video link and when i click at the link i want to download it,not being playing
Tuesday, September 18, 2018 9:17 AM -
User-821857111 posted
What's wrong with your first code example? The one that has the file name rather than the URL?
Tuesday, September 18, 2018 11:14 AM -
User1456523893 posted
i want use link another server not virtual file path
my first code example Done but for virtual file path not for link
Tuesday, September 18, 2018 11:28 AM -
User753101303 posted
Hi,
TransmitFile is for local files. It won't handle downloading from an http location. You'll have to download the file first possibly using HttpClient. For example http://www.tugberkugurlu.com/archive/efficiently-streaming-large-http-responses-with-httpclient
Tuesday, September 18, 2018 11:52 AM -
User-1716253493 posted
If you want read data from a web site then you can use system.net.webclient
Wednesday, September 19, 2018 12:52 AM -
User-893317190 posted
Hi bryar,
Money.Heist.S01E10.mp4 is not valid path for the method Response.TransmitFile. Valid path is like "D:\directory1\direcotry2\MoneyHeist.mp4". It is file system path.
So you should use method like Server.MapPath to get the valid file system path.
Just like
Response.TransmitFile(Server.MapPath("/images/example.mp4"))
The parameter of the MapPath method is the path t of your mp4 file relative to the project root.
Or you could also write like below.
Response.TransmitFile("/images/example.mp4")
Best regards,
Ackerly Xu
Wednesday, September 19, 2018 6:50 AM