在.net  中怎么实现文件的下载??

解决方案 »

  1.   

    WebClient webClinent = new WebClient();
    webClinent.DownloadFile(textBox1.Text,"下载文件.html");
      

  2.   

    给出文件地址不就ok拉?
    比如http://localhost/web/1.doc
    点击不就下载了?
    数据库存路径就ok了
      

  3.   

    下载1. C#: 
    /// <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();
    }
    2. vb.net
    Public Sub WriteDLWindow(ByVal strFileName As String, ByVal page As System.Web.UI.Page)
            Try
               If File.Exists(page.MapPath(strFileName)) Then
                   Dim TargetFile As FileInfo = New FileInfo(page.MapPath(strFileName))
                   '清除缓冲区流中的所有内容输出.
                   page.Response.Clear()
                   '向输出流添加HTTP头 [指定下载/保存 对话框的文件名]
                   page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + page.Server.UrlEncode(TargetFile.Name))

    '繁体格式
                    'page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8))                '向输出流添加HTTP头 [指定文件的长度,这样下载文件就会显示正确的进度
                    page.Response.AppendHeader("Content-Length", TargetFile.Length.ToString())
                    '表明输出的HTTP为流[stream],因此客户端只能下载.
                    page.Response.ContentType = "application/octet-stream"
                    '发送文件流到客户端.
                    page.Response.WriteFile(TargetFile.FullName)
                    '停止执行当前页
                    page.Response.End()
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Sub Set save file format: 
     Response.ContentType = "application/ms-excel";
      

  4.   

    我的连接到文件名 怎么他就把文件打开呢?
    是txt 文件就打开了
    其他的就报错!!
      

  5.   

    建一个.ashx(一般处理程序)
    我这是个下载图片的程序,弹出下载对话框而不是在浏览器中显示,楼主参考一下
    //download.ashx<%@ WebHandler Language="C#" Class="Download" %>using System;
    using System.Web;/// <summary>
    /// 下载图片用的Handler
    /// </summary>
    public class Download : IHttpHandler {
        
        public void ProcessRequest (HttpContext context) 
    {
    string path = context.Request.QueryString["image"];
    string ext = System.IO.Path.GetExtension( path );
    string filename = context.Request.QueryString["title"];

    context.Response.ContentType = "image/jpeg";
    context.Response.Charset = "utf-8";
    context.Response.AppendHeader( "content-disposition", "attachment; filename=\"" + "文件名" + "\";" );
    context.Response.TransmitFile( path );
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }}