通过一个URI,如何实现从服务器下载文件的问题。 URI如果是File URI和 HTTP URI,如何去执行具体的下载?谁能给个具体代码和在线资源,100分就是你的。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+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"); 如果是File URI呢?上面的代码可行吗? 你要下载的文件是保存在服务器的站点所在的文件内还是在其他文件夹下?如果是站内文件夹你可以直接用超链接来下载文件<a href="http://网站/文件夹/要下载的文件名">如果是在其他文件夹下就可以参照“jc15271149(奶皮儿)”的方法,以文件流的方式来获取 我的是C/S结构的WinForm程序。在客户端会部署一个后台windows service执行下载,类似于windows操作系统的下载。把远程文件服务器上的文件通过file uri 或者http uri下载到客户端 System.net里面有方法直接下载文件的,走80端口 char*怎么转byte并保持源数据不受encode影响? VS2008【从元数据】的问题 C# 录音、播音 Ogg 在C#嵌入MapX控件作GPS系统中,如何定位经度纬度的坐标? 动态SQL,列名使用变量?谢谢 NET程序结束了,调用的外部EXE也结束 vs2005 一个奇怪的问题 random socket收发数据问题!高手请指教! 我为班兄喝彩----稍有吹捧之意(害羞状)散分! 如何计算最大公约数与最小公倍数 求解:一个usercontrol的事件怎么引发另一个usercontrol的方法?
{
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(奶皮儿)”的方法,以文件流的方式来获取