本帖最后由 sdc102015 于 2012-05-16 18:01:46 编辑

解决方案 »

  1.   

    参考:
    http://www.cnblogs.com/insus/articles/1411761.html
    http://www.cnblogs.com/insus/articles/2003336.html
      

  2.   

    //取数据表         
    DataRow objDataRow = 
    objMedia.GetFileByPrimaryKey(id).Rows[0];
    objMedia和id是什么?
      

  3.   

    参考我之前的下载代码:自己优化哈
    using System;
    using System.Collections;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;namespace Asiastar.NR.Ajax
    {
        /// <summary>
        /// $codebehindclassname$ 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class Handler1 : IHttpHandler
        {        public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";            string id = context.Request["id"].ToString();//获取资源的编号
                System.IO.Stream iStream = null;
                byte[] buffer = new Byte[10000];
                int length;
                long dataToRead;
                NRBLL.File bf = new Asiastar.NRBLL.File();
                Guid guid = new Guid(id);
                if (bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"] != null)//判断数据库路径是否存在  
                {
                    string filepath = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString();//获取资源完整路径    D:\资源文件\600cc139-14cf-448e-9e50-daa972d35e01.jpg
                    string Oidfilename = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FileNam"].ToString();//旧文件名称
                    //string filename = System.IO.Path.GetFileName(filepath);//获取文件名称+后缀名 600cc139-14cf-448e-9e50-daa972d35e01.JPG
                    //int index = filepath.IndexOf(".");
                    //string filetype = filepath.Substring(index).ToLower();//后缀名
                    //string newfilename = Oidfilename;
                    //string filepath1 = bf.FN_SerchPathByFileId(guid).Tables[0].Rows[0]["FilePath"].ToString().Substring(0,filepath.Length - 8);
                    try
                    {
                        string fileName = HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(Oidfilename));//解码(注意这里2层解码)
                        Oidfilename = Oidfilename.Replace("+", "%20");  //将“+”替换成“空格”
                        iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
                        dataToRead = iStream.Length;
                        context.Response.ContentType = "application/octet-stream";
                        context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(Oidfilename, System.Text.Encoding.UTF8));  //下载的时候下载原来的文件名称
                        while (dataToRead > 0)
                        {
                            if (context.Response.IsClientConnected)
                            {
                                length = iStream.Read(buffer, 0, 10000);
                                context.Response.OutputStream.Write(buffer, 0, length);
                                context.Response.Flush();
                                buffer = new Byte[10000];
                                dataToRead = dataToRead - length;
                            }
                            else
                            {
                                dataToRead = -1;
                            }
                        }                }
                    catch (Exception ex)
                    {
                        NR.Error.Log.LogType(ex.ToString());
                    }
                    finally
                    {
                        if (iStream != null)
                        {
                            iStream.Close();
                        }
                    }
                }
                else
                {
                    NR.Error.Log.LogType("找不到文件!");
                }
            }
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
      

  4.   


     public static void DownLoadFile(string file)
        {
            HttpContext.Current.Response.Clear();
            System.IO.FileInfo finfo = new System.IO.FileInfo(file);
            if (!finfo.Exists)
            {
                oJavaScript.Alert("文件不存在");
                return;
            }
            else
            {
                string reportfile = finfo.FullName;
                string filename = finfo.Name;
                HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode(filename,System.Text.Encoding.UTF8));
                HttpContext.Current.Response.WriteFile(reportfile);
                HttpContext.Current.Response.End();
            }
        }
    上面的代码,我这里可以
      

  5.   

    错误是这个意思:
    Sys.WebForms.PageRequestManagerParserErrorExeception:从服务器收到的消息不能被解析。这种错误的常见原因是响应时调用细节修改:误差解析附近'□ □ □ □
      

  6.   

    直接 Response.Redirect   转像地址试试,你用UpdatePanel 了?
      

  7.   

    http://hi.baidu.com/a_magic/blog/item/2d9c2811fe90f9cca7ef3fa8.html 参考这个
      

  8.   

    好消息:
    大功告成!分享下:

    我建了个一般处理程序,代码如下:
    public class FileDownLoad : IHttpHandler 
    {     
    public void ProcessRequest(HttpContext context)     
    {         
    System.IO.FileInfo file = new System.IO.FileInfo(context.Request["filepath"].ToString());         context.Response.ContentType = "image/pic/pdf/bmp/png/gif/jpg/swf"; //例: "image/gif"         context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + HttpUtility.UrlEncode(file.Name) + "\"");         context.Response.TransmitFile(System.Web.Hosting.HostingEnvironment.MapPath(context.Request["filepath"].ToString()));  //常用方法, 大文件需换成Stream分段下载     }      public bool IsReusable     
    {         
    get         
    {             
    return true;         
    }     

    }
    然后在下载事件中写如下代码:
    Response.Redirect("FileDownLoad.ashx?filepath="+filePath);“FileDownLoad.ashx”为我创建的一般处理程序页面,“filePath”为传过去的虚拟路径
    跟三楼的差不多,谢谢各位了啊……