/// <summary>
/// 获取服务器路径(host地址+目录名)
/// </summary>
private static string UrlSuffix
{
get
{
如 localHost + XkBbsNet
return HttpContext.Current.Request.Url.Host +":"+ HttpContext.Current.Request.Url.Port.ToString() + HttpContext.Current.Request.ApplicationPath;
}
}
/// <value>
/// Property UrlBase is used to get the prefix for URLs.
/// </value>
public static String UrlBase
{
get
{
return @"http://" + UrlSuffix;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string path = UrlBase + "//temp//通迅录.xls";
string strPath = Server.MapPath("~/temp/通迅录.xls");
Response.Clear();
FileStream fs = new FileStream(strPath, FileMode.Open, FileAccess.Read);
Response.ContentType = "application/octet-stream";
Response.Headers.Add("Content-Disposition", "attachment;filename=" + path);
long dataLengthToRead = fs.Length;
byte[] buffer = new byte[fs.Length];
while (dataLengthToRead > 0 && Response.IsClientConnected)
{
int lengthRead = fs.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, lengthRead);
Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
}
Response.Close();
}