日期:2014-05-19  浏览次数:20745 次

通过一个URI,如何实现从服务器下载文件的问题。
URI如果是File   URI和   HTTP   URI,如何去执行具体的下载?谁能给个具体代码和在线资源,100分就是你的。

------解决方案--------------------
public static void DownloadFile(string physicalFilePath)
{
FileStream stream=null;
stream = new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufSize = (int)stream.Length;
byte[] buf = new byte[bufSize];

int bytesRead = stream.Read(buf, 0, bufSize);
HttpContext.Current.Response.ContentType = "application/octet-stream ";
HttpContext.Current.Response.AppendHeader( "Content-Disposition ", "attachment;filename= "+System.IO.Path.GetFileName(physicalFilePath));
HttpContext.Current.Response.OutputStream.Write(buf, 0, bytesRead);
HttpContext.Current.Response.End();
}

--------------
DownloadFile(@ "c:\aa.zip ");
------解决方案--------------------
你要下载的文件是保存在服务器的站点所在的文件内还是在其他文件夹下?
如果是站内文件夹你可以直接用超链接来下载文件
<a href= "http://网站/文件夹/要下载的文件名 ">
如果是在其他文件夹下就可以参照“jc15271149(奶皮儿)”的方法,以文件流的方式来获取
------解决方案--------------------
jc15271149(奶皮儿) 应该是可行的
------解决方案--------------------
System.net里面有方法直接下载文件的,走80端口