Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I need to create a page that enables the user to download the files from his directory depending upon his username. So, each user has its own specific directory. I have been able to display the files using DataGrid and put a download button next to each row (Asp:ButtonColumn) but I am unable to trigger the download. I have created a subroutine that enables the download using file streams, and I want the button to trigger that sub whenever the user clicks on it. Please help! Also plz. provide the code if possible

 

Regards,

Noorul

  • 2 weeks later...
Posted
What you need to do is create an Http Handler (.ashx) file. You can pass the file path to this handler in the QueryString. You then need to set the appropriate value for the ContentType property of the HttpResponse. Here's an example for an MS Word document:
byte[] bytes = null; // your file bytes here...

context.Response.ContentType = "application/ms-word";
context.Response.AddHeader("content-disposition", "inline;filename=test.doc");
context.Response.BinaryWrite(bytes);

Look around online for "HTML Content Type" for the right value for your specific file type.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...