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

I want to design a usercontrol where the user will be able to upload a file(.pdf/.txt/.jpeg)-which i was able to build using FileUpload control, but my problem is how to build a control where the user can see a list of uploaded file and click on it to download it. I am using Linq2Sql and have a table with a column Asset as byte[] to store the uploaded files.

I need sample Markup and Code Behind that can help me achieve this.

Thank you,

Chetan.
Posted
Updated 7-Jul-11 14:42pm
v2
Comments
Member 10658172 10-Mar-14 10:39am    
i want code and form design for file upload and download

You read the bytes from the DB and use Response.BinaryWrite to send the file down, making sure you set the header as well.

VB
Response.ClearContent()
                  Response.ClearHeaders()
                  Response.AddHeader("Content-Length", b.Length.ToString)
                  Response.ContentType = ContentType
                  Response.BinaryWrite(b)
                  Response.Flush()
                  Response.Clear()


Something like that, where b is your array of bytes.
 
Share this answer
 
Comments
cnjadhav 7-Jul-11 16:56pm    
can you explain me the following:
Response.AddHeader("Content-Length", b.Length.ToString)
and what control do you suggest for frontend(hyperlink/Gridview)?
Christian Graus 7-Jul-11 20:50pm    
You can use any control you want. b is a byte array. That line is telling the Response object to write the length of the file being downloaded. This is VB.NET, so add semicolons to make it C# :-)
cnjadhav 8-Jul-11 12:25pm    
how do i call the array of bytes, from a method like Employee.GetAll() with the column with bytes is EmployeePicture???
cnjadhav 8-Jul-11 12:28pm    
i mean how do i use FileInfo or the DirectoryInfo(server.MapPath(????callthebytearray)) to get the array of bytes?
i able to design the form in file upload who to write code for it
 
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