this.Accessories.InnerHtml = "<a href=<%=FileDownload(FileUpload/" + ntmbulletin.FileUpload + "%>>" + ntmbulletin.FileUpload + "</a>";

解决方案 »

  1.   

    高手 是这样的
    this.Accessories.InnerHtml = "<a href=<%=FileDownload(FileUpload/" + ntmbulletin.FileUpload + "%>>" + ntmbulletin.FileUpload + "</a>";
    我想输出到前台  实现下载  但是发现有文本文件下载不了的问题呀  所以就想用流
    能不能在此基础上指点
      

  2.   

    string filePath = Server.MapPath("");
    FileStream fs = new FileStream(filePath, FileMode.Open);
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment;   filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
    Response.BinaryWrite(bytes);
    Response.Flush();
    Response.End();
      

  3.   

    高手  不要再发这个了
    this.Accessories.InnerHtml = "<a href=<%=FileDownload(FileUpload/" + ntmbulletin.FileUpload + "%>>" + ntmbulletin.FileUpload + "</a>";
    必须要得到怎么调用你哪个方法
    哪个方法我早知道了
    可以目前我的思路怎么调用呢
      

  4.   

    你把FileDownload返回一个字符串,再赋给FileStream fs = new FileStream(filePath, FileMode.Open);
      

  5.   


    高手   高手   AJAX调用的时候老出错
      

  6.   


    1:this.Accessories.InnerHtml = "<a href=\"#\" onclick=\"javacript:FileDownload('" + ntmbulletin.FileUpload + "')\">" + ntmbulletin.FileUpload + "</a>";2:function FileDownload(filename)
    {
      PageService.FileDown(filename,TrueOrFalse,OnFailded);
    }3: [WebMethod(EnableSession = true)]
      public bool FileDown(string fileName)
      {
      string serFile = HttpContext.Current.Server.MapPath("~/FileUpload/") + fileName; // 服务器上存放文件的地址
      HttpContext.Current.Response.Clear();
      HttpContext.Current.Response.AddHeader("Content-Type", "text/plain");
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
      HttpContext.Current.Response.WriteFile(serFile); // 将文件以流的形式传输
      HttpContext.Current.Response.End();
      return true;
      }
    老提示 调用失败终止进程
    是不是AJAX不能处理这块
    可我不用AJAX交互 用什么呢
      

  7.   

        .提供一个 解决思路,你可以新建一个下载的页面,点击的时候弹出那个画面,直接用window.open() 打开就行了,当然了把需要的参数一起传过去.你可以试下。然后再那个新建的页面下 执行那段代码.
      

  8.   

     protected void Page_Load(object sender, EventArgs e)
            {
                //禁止缓存
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                if (!IsPostBack)
                {                string wuliname = Request["wuliname"].ToString();
                    string path = Request["wuliname"].ToString();
                    string leibie="";
                    if (Request["leibie"] != null)
                    {
                        leibie = Request["leibie"].ToString();
                    }                string a = UPLOADNAME + "/" + leibie + "/" + wuliname;
                    string luojiname = Request["luojiming"].ToString();
                    string workpath = Server.MapPath(a);
                    System.IO.FileInfo file = new System.IO.FileInfo(workpath);                if (file.Exists)
                    {
                       
                        Response.Clear();//清除缓冲区流中的所有内容输出
                        Response.ClearHeaders();//清除缓冲区流中的所有头,不知道为什么,不写这句会显示错误页面
                        Response.ContentType = "application/octet-stream";//设置输出类型,应用于所有文件
                        Response.Charset = "utf-8";
                        //Response.ContentType = "application/x-zip-compressed";
                        //将 HTTP 头添加到输出流
                        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Request.ContentEncoding.GetBytes(luojiname)));//一定要写,不写出错
                        Response.TransmitFile(a);//以上将指定的文件直接写入 HTTP 内容输出流。
                        Response.End();//将当前所有缓冲的输出发送到客户端,这句户有时候会出错,可以尝试把这句话放在整个函数的最后一行。
                        
                    }
                    else
                    {
                        AlertClose(up1, "不存在该文件,下载失败", true);
                    }
                    ScriptManager.RegisterStartupScript(up1, typeof(UpdatePanel), "initRadioChecked", "window.close();", true);
                }
            }这是我原来做过的一个项目中的写法 前台 什么都没有。
      

  9.   

    Ajax肯定会出错的,应该打开一个新窗口下载
    this.Accessories.InnerHtml = "<a href='??'>" + ntmbulletin.FileUpload + "<a>";
      

  10.   

    public byte[] Down(string filename)
     {
     string filepath = Server.MapPath("File/") + filename;
     if (File.Exists(filepath))
     {
     try
     {
     FileStream s = File.OpenRead(filepath);
     return ConvertStreamToByteBuffer(s);
    }
     catch
     {
     return new byte[0];
    }
    }
     else
     {
     return new byte[0];
    }
    }
    }