.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to Download file from a gridview upon clicking a hyperlink

Posted By:Ashutosh Jha       Posted Date: August 31, 2014    Points: 40    Category: ADO.NET    URL: http://www.dotnetspark.com  

this code explains how we can bind the grid so that upon clicking of hyperlink we can download any file-.
 

This code explains how we can bind the grid so that upon clicking of hyperlink we can download any file-


 protected void Page_Load(object sender, System.EventArgs e) {
        string root = "C:\\Inetpub\\wwwroot\\Folder\\";
        string filepath = "C:\\Inetpub\\wwwroot\\folderName\\filename.docx";
        if ((File.Exists(filepath) && filepath.StartsWith(root))) {
            string filename = Path.GetFileName(filepath);
            Response.Clear();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", ("attachment; filename=\"" 
                            + (filename + "\"")));
            Response.Flush();
            Response.WriteFile(filepath);
     
        }
    }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend