In this article we are going to see How to
download different types of file from the server. Follow the steps and comments
above code for clear understanding.
File Types like: PDF, TXT, XLS etc
Design View:

Used Namespace:
using
System;
using
System.Web;
Step 1 : This is used to get Project Location to download File inside the
Current Project.
///
<summary>
/// This is used to
get the current Project Location.
///
</summary>
public static
string ServerMapPath(string
path)
{
return
HttpContext.Current.Server.MapPath(path);
}
Step 2: Next Step, we have to get the current response.
///
<summary>
/// This is used to
get Current Response.
///
</summary>
public static
HttpResponse GetHttpResponse()
{
return
HttpContext.Current.Response;
}
Step 3: This method Helps to download any type of File within the server
by passing filename in parameter.
/// <summary>
/// This is used to download file from server.
/// </summary>

Amit MhaslePosted Aug 7, 2018, 8:03 AM
Code Not working
Dennis KumarPosted Apr 20, 2018, 2:32 AM
I unable to download using this, in "res.WriteFile(filePath);" throws error. Please suggest your solution......!
Kumar SambhavPosted Sep 13, 2012, 8:24 AM
Thank You Sir, Nice codding ....