Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a download link button. on it i performing downloading of pdf file. its perfectly perform downloading. but if a linkbutton with in Gridview with same work not performing downloading.

Can u tell me why and solution of that problem.
C#
try { 
string contentType = ""; 
//Get the physical path to the file. 
string invoice = "~/Invoice/" + DropDownList1.SelectedItem.ToString() + ".pdf"; 
string FilePath = HttpContext.Current.Server.MapPath(invoice); 
string fileExt = Path.GetExtension(invoice).Split('.')[1].ToLower(); 

if (fileExt == "pdf") 
{ 
 //Set the appropriate ContentType. 
 contentType = "Application/pdf"; 
} 

//Set the appropriate ContentType. 
Response.ContentType = contentType; 
Response.AppendHeader("content-disposition", "attachment; filename=" + (new FileInfo(invoice)).Name); 
//Write the file directly to the HTTP content output stream. 
Response.WriteFile(FilePath); 
Response.End(); 
} 
catch 
{ 
 //To Do 
}

Thanx in advance
Posted
Updated 10-Nov-11 1:11am
v3
Comments
Anuja Pawar Indore 10-Nov-11 6:12am    
Its better you provide your code where you are facing problem
koolprasad2003 10-Nov-11 6:12am    
what code you have done ? can you post your code ?
soniya sangal 10-Nov-11 6:15am    
its my code its working properly,but on commnd of link button with in gridview its not working
mhamad zarif 10-Nov-11 6:32am    
inside what event are you putting this code ?
Jayaraman Ambri 10-Nov-11 6:33am    
Normally it will be in link button clicked event. But for gridview in which event you have put this above code? Is the event triggering? What is the error you are getting? Or whether the control enters the event method?

1 solution

this problem is because of ypu are binding data at page load and for that you have to use a Page property isPostback and not to bind data....in grid view..
 
Share this answer
 
Comments
soniya sangal 10-Nov-11 7:00am    
me not binding data on page load
binding data with gridview on selectedindexchange of dropdownlist
nishantcomp2512 10-Nov-11 7:20am    
debug and check what the value of DropDownList1.SelectedItem.ToString()
soniya sangal 10-Nov-11 7:34am    
dropdown list returna value properly
nishantcomp2512 10-Nov-11 8:36am    
means its correct selection...
soniya sangal 10-Nov-11 23:14pm    
yes

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