原来asp都是传值过去嘛。看不到文件位置。然后直接就能下载的。拿.net 怎么做呢?

解决方案 »

  1.   

    Dim FileName As String '文件的路径
            FileName = Server.UrlDecode(filePath)     
            If File.Exists(FileName) Then
                Dim fi As New FileInfo(FileName)
                Response.Clear()
                Response.ClearHeaders()
                Response.Buffer = False              Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8))            Response.AppendHeader("Content-Length", fi.Length.ToString())
                Response.ContentType = "application/octet-stream"
                Response.WriteFile(destFileName)
                Response.Flush()
                Response.Clear()
              
            Else
                Response.Write("<script langauge=javascript>alert('文件不存在!');history.go(-1);</script>")
                'Response.End()
            End If
            ' File.Delete()        Response.Write("<script language='javascript'>alert('" & Server.MapPath(".") + "\AttachFiles\tmp\" + NewDirName + Username & "!');</script>")
         --我的一段程序,给你参照
      

  2.   

    55555555555555555555英雄~~你拿个C#做一下好不好?vb的看到头都大了。
      

  3.   

    vb转成c#可以到一下网址:
    http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx前两天刚从网上看到的~~~挺好用的~~试试吧!!!
      

  4.   

    string FileName; 
    FileName = Server.UrlDecode(filePath); 
    if (File.Exists(FileName)) { 
     FileInfo fi = new FileInfo(FileName); 
     Response.Clear(); 
     Response.ClearHeaders(); 
     Response.Buffer = false; 
     Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8)); 
     Response.AppendHeader("Content-Length", fi.Length.ToString()); 
     Response.ContentType = "application/octet-stream"; 
     Response.WriteFile(destFileName); 
     Response.Flush(); 
     Response.Clear(); 
    } else { 
     Response.Write("<script langauge=javascript>alert('文件不存在!');history.go(-1);</script>"); 

    Response.Write("<script language='javascript'>alert('" + Server.MapPath(".") + "\\AttachFiles\\tmp\\" + NewDirName + Username + "!');</script>");没错吧?