朋友问起怎么实现文件下载的功能。
实现之后贴出源码如下:
private
void
downLoad(
string
filename)
{
string path = Server.MapPath( " download/ " ) + filename;
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.Clear();
Response.AddHeader( " Content-Disposition " , " attachment;filename= " + Server.UrlEncode(filename));
Response.AddHeader( " Content-Length " ,fi.Length.ToString());
Response.ContentType = " application/octet-stream;charset=gb2321 " ;
Response.WriteFile(fi.FullName);
Response.Flush();
Response.Close();
}
}
{
string path = Server.MapPath( " download/ " ) + filename;
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.Clear();
Response.AddHeader( " Content-Disposition " , " attachment;filename= " + Server.UrlEncode(filename));
Response.AddHeader( " Content-Length " ,fi.Length.ToString());
Response.ContentType = " application/octet-stream;charset=gb2321 " ;
Response.WriteFile(fi.FullName);
Response.Flush();
Response.Close();
}
}