想实现这样的功能,数据库中有一个文件的真实名称(别人上传时的名),还有一个自动生成的名,然后当别人点击链接后,会出现另存为(真实名称)文件的一个对话框。

解决方案 »

  1.   

    =========
    public static bool DownloadAttachment(string filePath)
    {
    try
    {
    FileInfo file = new FileInfo(filePath);
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.Buffer = false;
    string strHadFileName = System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes(file.Name));
    HttpContext.Current.Response.ContentType = "application/octet-stream";
    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strHadFileName);
    HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
    string strFullName = file.FullName;
    HttpContext.Current.Response.WriteFile(strFullName);
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
    }
    catch
    {
    return false;
    }
    return true;
    }
      

  2.   

    >> HttpContext.Current.Response.ContentType = "application/octet-stream";
    这句话可能要修改:HttpContext.Current.Response.ContentType = "application/x-download";