c# - How can I force <a> links to files trigger download in the browser (and not open) -


i knowt may repeated question couldn't find solution case.

here's doing:i want create page admin of site can upload files , make description each file,and users can download these files.i created admin page fileupload control saves files in downloads/files.then created database 3 columns: 1-downloadtitle 2-downloadmain 3-name.the admin can enter download title , download main(the description of file) each file.and name column filled automatically uploaded file's name. here did download page(after getting data database using code behind):

<asp:repeater id="downloadsrepeater" runat="server">     <itemtemplate>         <div class="downloadtitle"><%#eval("downloadtitle") %></div>         <div class="downloadmain"><%#eval("downloadmain") %>             <div class="downloadbuttom" dir="ltr"><a href="/downloads/files/<%#eval("name") %>">download</a></div>         </div>     </itemtemplate>     <separatortemplate>         <div class="separator"></div>     </separatortemplate> </asp:repeater> 

you can idea of how page looks form above code(i don't want download links redirect user page.i want users click download , the file gets downloaded!) method used working doc files, not working pdf files example!(pdf files opened browser instead of download) want know if theyre's way of doing way want it?

as far know not possible setting special string href property of <a> tag.

but can desired behaviour replacing link asp.net linkbutton , postback in call following method:

public static void downloadfile(string filename, string path) {     response.contenttype = "application/unknown";     response.appendheader("content-disposition", "attachment; filename=" + filename);     response.transmitfile(path);     response.end(); } 

path full path file want send client , filename name file should have when sent (can different original name).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -