/// <summary>
/// 下载
/// </summary>
/// <param name="fileName"></param>
public void DownloadFile(string fileName)
{
string adminUploadFilePath = ConfigParameter.HomeUploadFilePath;
if (!string.IsNullOrEmpty(fileName))
{
string filePath = Path.Combine(string.Format(@"{0}/OnlineSubmission/files", adminUploadFilePath), string.Format(@"{0}", fileName));
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists == true) //如果存在文件
{
byte[] buffer = new byte[1024 * 1024]; //每次读取1024 * 1024大小的数据
Response.Clear();
FileStream fs = File.OpenRead(filePath);
long dataToRead = fs.Length;
// Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
Response.AppendHeader("Content-Length", fs.Length.ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
while (dataToRead > 0)
{
int readLength = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, readLength);
Response.Flush();
dataToRead = dataToRead - readLength;
}
Response.Flush();
fs.Dispose();
Response.Close();
}
}
}
/// 下载
/// </summary>
/// <param name="fileName"></param>
public void DownloadFile(string fileName)
{
string adminUploadFilePath = ConfigParameter.HomeUploadFilePath;
if (!string.IsNullOrEmpty(fileName))
{
string filePath = Path.Combine(string.Format(@"{0}/OnlineSubmission/files", adminUploadFilePath), string.Format(@"{0}", fileName));
FileInfo fileInfo = new FileInfo(filePath);
if (fileInfo.Exists == true) //如果存在文件
{
byte[] buffer = new byte[1024 * 1024]; //每次读取1024 * 1024大小的数据
Response.Clear();
FileStream fs = File.OpenRead(filePath);
long dataToRead = fs.Length;
// Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName));
Response.AppendHeader("Content-Length", fs.Length.ToString());
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
while (dataToRead > 0)
{
int readLength = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, readLength);
Response.Flush();
dataToRead = dataToRead - readLength;
}
Response.Flush();
fs.Dispose();
Response.Close();
}
}
}