C#|C# 后台图片重命名下载


///
/// 图片重命名下载
///
/// 图片物理路径
/// 图片名称(全称包括后缀名),如你想要你的图片以身份证命名此处就是 130XXXXXXX.jpg
public void Download(string filePath, string fileName)
{
Encoding encoding;
string outputFileName = null;
fileName = fileName.Replace("'", "");
【C#|C# 后台图片重命名下载】string browser = Request.UserAgent.ToUpper();
if (browser.Contains("MS") == true && browser.Contains("IE") == true)
{
outputFileName = HttpUtility.UrlEncode(fileName);
encoding = Encoding.Default;
}
else if (browser.Contains("FIREFOX") == true)
{
outputFileName = fileName;
encoding = Encoding.GetEncoding("GB2312");
}
else
{
outputFileName = HttpUtility.UrlEncode(fileName);
encoding = Encoding.Default;
}
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.Charset = "UTF-8";
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = encoding;
Response.AddHeader("Content-Disposition", "attachment; filename=" + outputFileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
//return new EmptyResult();
}

    推荐阅读