在输出文件地地方使用的代码: string path = request.PhysicalPath;//获取客户端请求的文件的物理地址 if (File.Exists(path)) { string fileName = System.IO.Path.GetFileName(path); // 获取文件的名字 if (Request.UserAgent.Contains("MSIE") || Request.UserAgent.Contains("msie")) { // 如果客户端使用 Microsoft Internet Explorer,则需要编码 fileName = ToHexString(fileName); // 如果使用 fileName =Server.UrlEncode(fileName); 则会出现上文中出现的情况 } Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName); Response.WriteFile(path); Response.End(); }
1