Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...friends,

In my web application Admin Posts Jobs For which at user Panel User can apply for various posts with uploading resume file (in .doc, .pdf, .rtf formats only) and some details. I have save resume file (.doc, .pdf, .rtf) in my directory folder and file_path and other information in database table.

Then I displayed the applied user info. in GridView at admin panel but now i want to down load resume file at button click....

How can i do this...

I have allowed user to upload resume in .doc, .pdf, .rtf file formates....

Please help me...

Thanks
Posted

Add in Gridview

<asp:templatefield headertext="Download" xmlns:asp="#unknown">
<itemtemplate>
<asp:imagebutton id="btnDownload" runat="server" tooltip="Download" imageurl="~/Images/icon/Download.ico">
CommandName="Download" CommandArgument='<%# Bind("ReportName") %>' />

<itemstyle width="10%">



Add below code in row command

protected void gvReport_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName == "Download")
{
string CommandArgument = e.CommandArgument.ToString();


string path = "./";
string serverPath = HttpContext.Current.Server.MapPath(path);
string pdfpath = serverPath + "QuarterlyReports\\" + CommandArgument + ".pdf";

//Response.Redirect(fileName);
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(pdfpath));
Response.TransmitFile(pdfpath);
//HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();

}
catch (Exception ex)
{

}
 
Share this answer
 
protected void gd_cat_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "downLoad")
{
DataTable dt = new DataTable();
Int32 id = Convert.ToInt32(e.CommandArgument);
p.Admin_Flag = 8;
p.Id = id;
p.Post_Date = System.DateTime.Now.Date;
dt = b.Job_Applied_GridShow(p);
if (dt.Rows.Count > 0)
{
string filepath = "~/" + dt.Rows[0]["file_path"].ToString();


//.......................................................
string path = Server.MapPath(filepath);
//get physical file path from server
string name = Path.GetFileName(path);
//get file name
string ext = Path.GetExtension(path);
//get file extension
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
// case ".htm":
// case ".html":
// type = "text/HTML";
// break;
// case ".txt":
// type = "text/plain";
// break;
// case ".GIF":
// type = "image/GIF";
// break;
case ".pdf":
type = "Application/pdf";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
Default:
type = "";
break;
}
}
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
if (type != "")
{
Response.ContentType = type;
Response.WriteFile(path);
Response.End(); //give POP to user for file downlaod
}

}

}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900