Active5 years ago
In my application I want to give user the option to download a PDF file. In my code, the file gets opened by browser; however, I want the file to be downloaded. Here's my code:
Controller
Here's how I'm using it in dropdown menu.
ASP.NET provides a built-in user database with support for multi-factor authentication and external authentication with Google, Twitter, and more. Active community and open-source. Get quick answers to questions with an active community of developers on StackOverflow. ASP.NET was released in 2002 as a successor to Classic ASP. ASP.NET pages have the extension.aspx and are normally written in C# (C sharp). ASP.NET 4.6 is the latest official version of ASP.NET.
ASP.NET MVC App Structure.URLs mapped to controller classes.Controller –handles requests, –executes appropriate logic and –calls a View to generate HTML response.URL routing –ASP.NET routing engine (flexible mapping) –Support for defining customized routing rules –Automatic passing/parsing of parameters 9 of 114. You can use of iTextSharp dll is a C# port of iText, an open source Java library for PDF generation and manipulation. It can be used to create PDF documents from scratch, to convert XML to PDF (using the extra XML Worker DLL), to fill out interactive PDF forms, to stamp new content on existing PDF documents, to split and merge existing PDF documents, and much more. When click on link of download button for pdf file it will open on browser but i want to download it not on open on browser, i can not want open it on browser. So plz give solution of this in asp.net thank you in advance Mohit Agarwal.
View:
By clicking on 'Download', the file gets opened browser.
tereško53.4k2121 gold badges7979 silver badges137137 bronze badges
user3853986user3853986
3 Answers
Set your content type to 'application/octet-stream' so the PDF plugin won't try to pick it up and display it. Then the browser will handle it as a file download.
Eric MattisonEric Mattison
Download Files from Web:
This example shows how to download files from any website to local disk. The simply way how to download file is to use WebClient class and its method DownloadFile. This method has two parameters, first is the url of the file you want to download and the second parameter is path to local disk to which you want to save the file.Download File Synchronously
The following code shows how to download file synchronously. This method blocks the main thread until the file is downloaded or an error occur (in this case the WebException is thrown).[C#]:
Download File Asynchronously:To download file without blocking the main thread use asynchronous method DownloadFileAsync. You can also set event handlers to show progress and to detect that the file is downloaded.[C#]:
ref: http://www.csharp-examples.net/download-files/
Power ManPower Man
Browser will try to show the file unless you specify not to.
Try Adding ContentDisposition before returning File.
Yusuf DemiragYusuf Demirag
Not the answer you're looking for? Browse other questions tagged c#asp.net-mvcpdfdownload or ask your own question.
Active5 years, 10 months ago
I have some customers in a gridview. When I click on the customers I can get their names in a textbox. There is also a corresponding pdf document which should also be available if the user desires.
My problem is that I need to know who to open a pdf document using C# and asp.net. I have to use a variable name as the name of pdf document, for example when the click on a button 'open variable CustomerName.pdf'.
I need to open a pdf file in a new window for viewing
thanks this works asp:HyperLink runat='server' NavigateUrl='~/customerUnit/Customer.pdf' Target='_blank'>HyperLink
Red dead revolver xbox iso. Apr 23, 2018 Red Dead Revolver PS2 Gameplay Release Date: May 4, 2004 Platforms: PlayStation 2, Xbox Red Dead Revolver Intro. Apr 18, 2018 Red Dead Revolver (PS4) - Gameplay Walkthrough Part 1 - Prologue 1080p 60fps - Duration: 57:51. Shirrako 212,330 views. COMO BAIXAR, INSTALAR E CONFIGURAR EMULADOR DE PS2 EM TODOS OS. Download the Red Dead Revolver ROM for XBox. Filename: Red Dead Revolver !.7z. Works with Android, Windows, and Mac OS X devices. The outcome is Red Dead Redemption, a captivating new experience amusement that is a high water mark for both the western class and Rockstar Games. Red Dead Redemption is the otherworldly successor to Red Dead Revolver, the 2004 activity amusement for the first Xbox and PlayStation 2. If you haven't noticed yet, we have a retro game of the day feature (top-right of the screen) wherein we feature a new retro title every single day! Now, you can vote for your favorite games and allow them to have their moment of glory. Click on the button below to nominate Red Dead Revolver (USA) for Retro Game of the Day.
But I want to pass the pdf file as a variable 'Customer.pdf' should be 'VaribleCustmer.pdf'
user2791420
user2791420user2791420
closed as unclear what you're asking by freefaller, Dour High Arch, benni_mac_b, rene, LittleBobbyTablesDec 11 '13 at 19:45
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1 Answer
I agree with
@Ahmed
from the comments, you shouldn't over-think this:- Simply link to the
CustomerName.pdf
if your using a hyperlink. - Simply redirect to
the CustomerName.pdf
if your using a button
But I want to pass the pdf file as a variable 'Customer.pdf' should be 'VaribleCustmer.pdf'
Asp Markup:
Code behind:
medameda41k1111 gold badges7575 silver badges115115 bronze badges