Response.WriteFile只能输出本地文件
输出Internet上的文件用WebClient
WebClient wc = new WebClient();
byte[] filedata = wc..DownloadData("文件Url");
...
Response.BinaryWrite(filedata);
输出Internet上的文件用WebClient
WebClient wc = new WebClient();
byte[] filedata = wc..DownloadData("文件Url");
...
Response.BinaryWrite(filedata);
解决方案 »
- 请有经验的进来帮看看:MODEL类的实现方法?
- .net中如何使用谷歌企业邮局发送邮件
- 给一个功能比较全的BLOG下载。要求.net+sql写的。回答马上结贴。
- 怎样获取其它页面控件的选取值????
- 请问怎样用javascript来判断点击的是哪个imagebutton控件?
- 页面刷新后Reset Button 不能清空form 的TextBox中的内容!
- 请问<authentication mode="Forms">代表什么意思?
- 『怪问题』怎么实现 点击提交按钮 却不提交表单?
- 请问在datagrid里面如何增加记录???
- 帮我推荐一下
- 安装microsoft的ie webcontrol,怎么把他添加到工具拦里
- ShowModelDialog打开一个窗口用来选择图片上传?在IE5下,总是关闭不了,IE6下没有问题。代码如下。
{
WebClient wc = new WebClient();
try
{
byte[] FileData = wc.DownloadData(fileUrl);
Response.ClearHeaders();
Response.ClearContent();
Response.BinaryWrite(FileData);
Response.End();
}
catch( WebException exp )
{
throw new WebException( exp.ToString() );
}
}
示例调用:
WriteFile("http://expert.csdn.net/Expert/topic/2605/2605430.xm");
<%@ Page Language="VB" Debug="true"%>
<%@ Import NameSpace="System.IO" %>
<%@ Import NameSpace="System.Net" %>
<script runat="server">
Sub Button2_Click(s As Object,e As EventArgs)
DownloadFile_FormWeb("http://image2.sina.com.cn/home/temp/1_30-13-115_200312249442.GIF",true)
End SubSub DownloadFile_FormWeb(ByVal fileUrl As String, ByVal forceDownload As Boolean)
dim wc as WebClient = new WebClient()
dim FileData as byte() = wc.DownloadData(fileUrl)
Response.ClearHeaders()
Response.ClearContent()
Response.BinaryWrite(FileData)
Response.End()
End Sub
</script><form runat="server">
<asp:Button id="button2" onclick="Button2_Click" runat="server" Text="Sina Logo DownLoad"/>
</form>
Response.ClearContent()
Response.AppendHeader("content-disposition", _
"attachment; filename=" + name)
....
<%@ Page Language="VB" Debug="true"%>
<%@ Import NameSpace="System.IO" %>
<%@ Import NameSpace="System.Net" %>
<script runat="server">
Sub Button2_Click(s As Object,e As EventArgs)
DownloadFile_FormWeb("http://image2.sina.com.cn/home/temp/1_30-13-115_200312249442.GIF",true)
End SubSub DownloadFile_FormWeb(ByVal fileUrl As String, ByVal forceDownload As Boolean)
dim name as string = "http://image2.sina.com.cn/home/temp/1_30-13-115_200312249442.GIF"
dim wc as WebClient = new WebClient()
dim FileData as byte() = wc.DownloadData(fileUrl)
Response.ClearHeaders()
Response.ClearContent()
Response.BinaryWrite(FileData)
Response.ClearContent()
Response.AppendHeader("content-disposition", "attachment; filename=" + name)
Response.End()
End Sub
</script><form runat="server">
<asp:Button id="button2" onclick="Button2_Click" runat="server" Text="Sina Logo DownLoad"/>
</form>
dim myWebClient as WebClient = new WebClient()
'保证你的相关文件夹的写权限:(如下示例:e:\download文件夹必须有写权限)
myWebClient.DownloadFile(name,Server.MapPath("e:\download\a.gif"));
那就那上面几个说的,先用DownloadFile方法保存到服务器上,然后用FileStream读入的流中再输出DownloadData方法不行?晕,我测试看看
<%@ Import Namespace="System.Net" %>
<script language="VB" runat="server">
Sub Page_Load(src as object, e as EventArgs)
WriteFile("http://www.csdn.net/images/homeimage/csdn.gif")
End Sub
Sub WriteFile(fileUrl as string)
dim wc as WebClient = new WebClient()
dim FileData as byte() = wc.DownloadData(fileUrl)
Response.ClearHeaders()
Response.ClearContent()
Response.AppendHeader("content-disposition", "attachment; filename=" + "csdn.gif")
Response.BinaryWrite(FileData)
Response.End()
End Sub
</script>