1个回答
展开全部
这不就是个下载吗!private void CreateData(string fileName)
{
string filePath = Server.MapPath("QuestionPaters/" + fileName);//路径
byte[] data = null;
if (File.Exists(filePath))
{
FileStream fs = new FileStream(filePath, FileMode.Open);
data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(data);
Response.Flush();
Response.End();
}
else
{
divError.InnerText = "此试卷不存在或被移除";
}
}
{
string filePath = Server.MapPath("QuestionPaters/" + fileName);//路径
byte[] data = null;
if (File.Exists(filePath))
{
FileStream fs = new FileStream(filePath, FileMode.Open);
data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(data);
Response.Flush();
Response.End();
}
else
{
divError.InnerText = "此试卷不存在或被移除";
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询