点击的时候就可以下载?这个怎么弄呢?那个下载是一个超链接来的
我希望通过点击,然后传给一般处理程序实现下载,怎么弄呢?

解决方案 »

  1.   

    这个文件的位置不就可以了吗 <a href="http://.....//ssdsdsdsd.jpg"></a>
      

  2.   

    直接放文件路径,如果你是问后台的话:protected void Button1_Click(object sender, EventArgs e)
         {
            /*
              微软为Response对象提供了一个新的方法TransmitFile来解决使用Response.BinaryWrite下载超过400mb的文件时导致Aspnet_wp.exe进程回收而无法成功下载的问题。
        代码如下:
        */
             Response.ContentType = "application/x-zip-compressed";
             Response.AddHeader("Content-Disposition", "attachment;filename=CodeShark.zip");
             string filename = Server.MapPath("DownLoad/CodeShark.zip");
             Response.TransmitFile(filename);
         }
      

  3.   

    一般处理程序代码如下:
    public void ProcessRequest(HttpContext context)
        {
            if (context.Request["strPath"] != null && context.Request["strPath"].ToString() != "")
            {
                string strPath = context.Server.UrlDecode(context.Request["strPath"].ToString());
                string strName = System.IO.Path.GetFileName(strPath);
                //以字符流的形式下载文件
                FileStream fs = new FileStream(strPath, FileMode.Open);
                byte[] bytes = new byte[(int)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();
                context.Response.ContentType = "application/octet-stream";
                //通知浏览器下载文件而不是打开
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strName, System.Text.Encoding.UTF8));
                context.Response.BinaryWrite(bytes);
                context.Response.Flush();
                context.Response.End();
                
            }
        }
    下载两个字的代码如下:
    strSb.Append("<td><a href=\"DownLoadHandler.ashx?strPath=" + Server.UrlEncode(myFileInfo.FilePath) + "\">下载</a></td>");
    问题:为什么点那个下载的时候,就是下载DownLoadHandler.ashx而不是下载我想要的文件
      

  4.   

    一般处理程序代码如下:
    public void ProcessRequest(HttpContext context)
        {
            if (context.Request["strPath"] != null && context.Request["strPath"].ToString() != "")
            {
                string strPath = context.Server.UrlDecode(context.Request["strPath"].ToString());
                string strName = System.IO.Path.GetFileName(strPath);
                //以字符流的形式下载文件
                FileStream fs = new FileStream(strPath, FileMode.Open);
                byte[] bytes = new byte[(int)fs.Length];
                fs.Read(bytes, 0, bytes.Length);
                fs.Close();
                context.Response.ContentType = "application/octet-stream";
                //通知浏览器下载文件而不是打开
                context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strName, System.Text.Encoding.UTF8));
                context.Response.BinaryWrite(bytes);
                context.Response.Flush();
                context.Response.End();
                
            }
        }
    下载两个字的代码如下:
    strSb.Append("<td><a href=\"DownLoadHandler.ashx?strPath=" + Server.UrlEncode(myFileInfo.FilePath) + "\">下载</a></td>");
    问题:为什么点那个下载的时候,就是下载DownLoadHandler.ashx而不是下载我想要的文件
      

  5.   

    参考:http://www.cnblogs.com/qiangni/archive/2012/12/12/2814585.html