0

I have a table called tblfiles with columns

id             int

Name           varchar(50)    
ContentType    varchar(50)    
Data           varbinary(MAX)

the id is incremental, name is the name of the file being uploaded, Content type tells the type of the file being uploaded such as "application/PDF" or "application/ms-word" etc... and data is where the Binary data is being stored.

I have managed to upload data into the database.

I have added a gridview to display the data automatically binded (You know not manually which is only SELECT all from tblfiles) I want a column that will display a download hyperlink or button to download the file.

Remember all data is being stored in database not a folder!!

So How can I do this ??

aizaz
  • 3,056
  • 9
  • 25
  • 57
sam
  • 13
  • 7

3 Answers3

1

Try to create the Grid event OnRowDataBound method to create the links that refer the file from database.

You can use regular links with the href of the file or you can create buttons for the grid. If you create the buttons, you should also create the method for the Grid RowCommand.

Check these links:

http://www.dotnetgallery.com/kb/resource17-RowDatabound-event-tips-and-tricks-in-Gridview-control.aspx

How to change in a Gridview on RowDataBound event the value of an Eval() field

Community
  • 1
  • 1
Diego Murakami
  • 191
  • 1
  • 6
0

You can have a page for files

ex: www.website.com/download.aspx?id=12

You'll then need to change the http header to say it's a file to download with the data of that file.

Response.AddHeader("Content-disposition", "attachment; filename=" & filename)
Response.ContentType = "application/PDF"
Response.BinaryWrite(binaryData)
Response.End()

An other option could be to create a temporary file.

the_lotus
  • 12,668
  • 3
  • 36
  • 53
0

YOu need to add a link which executes a method (either have a hyperlink column or a templated column that contains a hyperlink). The link should execute a method which does something along these lines:

  1. Loads the corresponding binary data in memory
  2. Writes the binary stream into the response using Response.BinayWrite.

Make sure the response object has contentType set to "application/octet-stream" (look it up for the correct spelling, not sure about it) Make sure the response object has the following header: "Content-disposition", "attachment: filename=

cristi71000
  • 1,094
  • 2
  • 10
  • 16