日期:2014-05-17  浏览次数:20575 次

.net 网页开发中如何用代码实现下载功能

 我们在开发网站的时候,要为用户提供一个下载的功能,用户主要是通过浏览网站时,在些网站上下载,这个效果怎么现实。代码要详细的说明。

------解决方案--------------------
C# code

/**////   <summary>
///   文件下载
///   </summary>
///   <param   name= "FullFileName "> </param>
private   void   FileDownload(string   FullFileName)
...{
FileInfo   DownloadFile   =   new   FileInfo(FullFileName);  
Response.Clear();
Response.ClearHeaders();
Response.Buffer=false;
Response.ContentType= "application/octet-stream ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename= "   +HttpUtility.UrlEncode(DownloadFile.FullName,System.Text.Encoding.UTF8));
Response.AppendHeader( "Content-Length ",DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}

------解决方案--------------------
a标签
------解决方案--------------------
<a href="a.aspx?name=xx.doc">下载</a>

a.aspx里面写上面的代码就可以
FullFileName
参数写
String x = Server.MapPath("~/" + Request.QueryString["name"]);
FileDownload(x);
即可
xx.doc放在程序根目录下


------解决方案--------------------
直接链接文件就可以了
------解决方案--------------------
http://topic.csdn.net/u/20120425/11/21dc8e38-0888-4197-8ff0-a019fd2ffdd7.html