asp.net 客户端如何读取服务器端的文件,要求是先从服务器下载到本地的临时文件,在用本地的应用程序打开。
发布网友
发布时间:2022-04-28 13:24
我来回答
共1个回答
热心网友
时间:2023-10-10 06:28
这不就是个下载吗!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 = "此试卷不存在或被移除";
}
}
热心网友
时间:2023-10-10 06:28
这不就是个下载吗!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 = "此试卷不存在或被移除";
}
}
热心网友
时间:2023-10-10 06:28
这不就是个下载吗!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 = "此试卷不存在或被移除";
}
}