Response.WriteFile [英] Response.WriteFile

查看:147
本文介绍了Response.WriteFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个URL具有特定语法来下载文件。结果
<一href=\"http://www.hddownloader.com/?url=http://www.youtube.com/watch?v=N-HbxNtY1g8&feature=featured&dldtype=128\" rel=\"nofollow\">http://www.hddownloader.com/?url=http://www.youtube.com/watch?v=N-HbxNtY1g8&feature=featured&dldtype=128

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=128

用户输入在文本和$ P $文件名psses下载button.In单击事件的Response.WriteFile被称为该文件发送到客户端。

The user enters the file name in the textbox and presses the download button.In the click event the Response.WriteFile is called which sends the file to the client.

现在我想建立另一个网站与网页,用户在其中输入文件名和presses的下载按钮下载该文件。

Now I want to create another website with a page, in which the user enters the filename and presses the download button to download that file.

现在我希望利用针对第一个URL。我不想使用的Response.Redirect,因为这样一来,用户会知道,我使用mydownload.com。

Now I want to utilise the first URL for that. I dont want to use Response.Redirect, because by that way, the user will come to know that I am using mydownload.com.

我怎么能acheieve这一点。

How can I acheieve that.

一个方法是:当我们从微软的网站,一个小的弹出窗口下载的东西(没有关闭,最大化和最小化按钮),然后出现对话框保存

One way is : When we download something from microsoft's website, a small popup window(with no close, maximise and minimise button) and then the save dialog box appears.

如何实现这个或另一个来实现相同的

How to achieve this or another to achieve the same ?

推荐答案

您可以首先从远程位置下载文件中使用的 WebClient.DownloadFile

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");
}

如果你不想将文件保存到临时,你可以使用的 DownloadData 方法,然后流缓冲到响应。

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.

更新:

与第二方法实施例:

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();
}

这篇关于Response.WriteFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆