public static string ServerMapPath(string path)
{
return HttpContext.Current.Server.MapPath(path);
}
public static HttpResponse GetHttpResponse()
{
return HttpContext.Current.Response;
}
public static void DownLoadFileFromServer(string fileName)
{
try
{
string filePath = ServerMapPath(fileName);
HttpResponse res = GetHttpResponse();
res.Clear();
res.AppendHeader("content-disposition", "attachment; filename=" + filePath);
res.ContentType = "application/octet-stream";
res.WriteFile(filePath);
res.Flush();
res.End();
}
catch (Exception ex)
{
}
}
protected void Button2_Click(object sender, EventArgs e)
{
DownLoadFileFromServer("~/Storage/" + txtname.Text);
}
file need to be in same directory of website in some folder int this case folder name is Storage