C#asp.net 保存文件到本地

   private void DownFile(string filePath,string fileName)
    {
        FileInfo fileInfo =new FileInfo(filePath);
        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition","attachment;filename="+ fileName);
        Response.AddHeader("Content-Length", fileInfo.Length.ToString());
        Response.AddHeader("Content-Transfer-Encoding","binary");
        Response.ContentType ="application/octet-stream";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        Response.WriteFile(fileInfo.FullName);
        Response.Flush();
        Response.End();
    }

上面是类  下面是调用

    protected void Button1_Click(object sender, EventArgs e)
    {

        DownFile(Server.MapPath("18276863616.jpg"), "18276863616.jpg");

    }
}

webform