Response.WriteFile

后端 未结 1 739
借酒劲吻你
借酒劲吻你 2021-01-13 12:48

There is one URL with specific syntax to download a file.
http://www.hddownloader.com/?url=http://www.youtube.com/watch?v=N-HbxNtY1g8&feature=featured&dldtype=12

相关标签:
1条回答
  • 2021-01-13 13:24

    You could first download the file from the remote location on your server using WebClient.DownloadFile:

    using (var client = new WebClient())
    {
        client.DownloadFile("http://remotedomain.com/somefile.pdf", "somefile.pdf");
        Response.WriteFile("somefile.pdf");
    }
    

    or if you don't want to save the file temporary to the disk you could use the DownloadData method and then stream the buffer into the response.


    UPDATE:

    Example with the second method:

    using (var client = new WebClient())
    {
        var buffer = client.DownloadData("http://remotedomain.com/somefile.pdf");
        Response.ContentType = "application/pdf";
        Response.AppendHeader("Content-Disposition", "attachment;filename=somefile.pdf");
        Response.Clear();
        Response.OutputStream.Write(buffer, 0, buffer.Length);
        Response.Flush();
    }
    
    0 讨论(0)
提交回复
热议问题