string path = Server.MapPath(file.Path);
            System.IO.FileInfo files = new System.IO.FileInfo(path);            if (files.Exists)
            {
                Response.Clear();
                string s = HttpUtility.UrlEncode(System.Text.UTF8Encoding.UTF8.GetBytes(files.Name));
                Response.AddHeader("Content-Disposition", "attachment; filename=" + s);
                Response.AddHeader("Content-Length", files.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.WriteFile(files.FullName);
                Response.End();            }
            else
            {
                Response.Write("你所选中文件不存在!");
            }
出现错误说  不是有效的虚拟路径,不知道咋办了,请大家帮忙。是实现下载功能的。

解决方案 »

  1.   

    路径都用这个试试Server.MapPath(相对路径);
      

  2.   

    string path = Server.MapPath(file.Path);估计上面路径错了,可以这样用string path = HttpContext.Current.Server.MapPath("~/UpLoad/") + s_fileName; //s_fileName为文件名
    System.IO.FileInfo files = new System.IO.FileInfo(path); 
      

  3.   

    二楼的试过了,不行。url格式不正确。抓狂,试试三楼的看看
      

  4.   

    数据库里面存在文件的路径(paths),我存的是c:\files\aa.txt
    string path = HttpContext.Current.Server.MapPath(paths);
    不行了
      

  5.   

    调试把你现在用的path输出看下是什么路径?
      

  6.   

    文件应该先上传到服务器上面。数据库里面存文件名就行了aa.txt
      

  7.   

    如果是要用户自己可以上传文件的,就要做上传功能了。
    如果是固定的文件,就复制到服务器虚拟目录下面就行了,如在虚拟目录下面建立UpLoad文件夹,把文件放进去,数据库保存这个文件名,就可以像上面那样用了:string path = HttpContext.Current.Server.MapPath("~/UpLoad/") + s_fileName; //s_fileName为文件名
    System.IO.FileInfo files = new System.IO.FileInfo(path);
    //。其它代码