views:

34

answers:

2

I am using ASP.NET and C#.

I have made a document uploading page, In which use can upload their document. I am saving three fields in the database,

  1. Document Name [NVarchar]
  2. File [Image]
  3. DocumentType [NVarchar]

Now, I am able to add records in the database, successfully. Now I want to show it in the gridview, like DocumentName, DocumentType and a link to download the file.

I have tried by retrieving the records and assigning them to the gridview but I am getting only two columns.

A: 

You have to create a download handler that serves the actual file.

The handler can retrieve the Binary from the table and write is directly to the output stream.

The grid view would then point to this handler

Sruly
Can you please rediect to me to any example.I have no idea how to create download handlers.
Rahul
Can I use this ? http://aspnetupload.com/Quickstart/Download-From-File.aspxI'll write the code in the linkbutton click event.
Rahul
A: 

Since you are storing files in DB you will have to write code to read the file data, add appropriate header and do response.write

e.g.

on your LinkButton click handler the code will be something like

private void lnkDownload_Click(object sender,args)
{

//if you are using dataset the data will be of type byte array byte[]
//assuming you have assign the binary data to byte array

byte[] data;
Response.Clear(); //clear buffer
Response.ContentType = "image/gif"; //should be the MIME type of the document see http://www.w3schools.com/media/media_mimeref.asp for the complete list
Response.AddHeader("content-disposition", "attachment;filename=" + yourfilename);  //tell the browser the file is to be downloaded
Response.BinaryWrite(data);
Response.End();

}
ajay_whiz