How can I open & download pdf from a server folder in which it is saved by click on hyperlink of a gridview using c#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["id"] != null)
{
int File_link = int.Parse(Request.QueryString["id"].ToString());
GetDocuments(File_link);
}
}
}
protected void GetDocuments(int File_link)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~/PDF_File" + File_link));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
Grid_File.DataSource = files;
Grid_File.DataBind();
}
Viewpdfpage:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
<title></title>
</head>
<body>
<form id="form2" runat="server">
<div>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string filePath = Server.MapPath("~/PDF_File" + File_link);
Response.ContentType = "Application/pdf";
Response.WriteFile(filePath);
Response.End();
}
}
I am getting the error :
Access to the path 'F:\wip\wip\PDF_File' is denied
yet the path is right.
Response.WriteFile (filepath) is giving error.
kindly help in this.