Recently I’m working on the Web Application project. In which i have to display PDF file in from our local server folder. For that, I have followed the below step
- Download PDF file from a Link.
- Downloaded PDF file in the local folder if you working on a web application then you need to save it in the server folder.
- Display PDF files from the local folder.
Html Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="Index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Click To Download Pdf" OnClick="Button1_Click" />
<br />
<br />
<iframe runat="server" id="iframepdf" height="600" width="800" src=""> </iframe>
</div>
</form>
</body>
</html>
Backend Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string filesave = Server.MapPath("~/DownloaddFiles/mypdffile.pdf");
string pdfurl = "https://www.learningcontainer.com/wp-content/uploads/2019/09/sample-pdf-file.pdf";
DownLoadpdfFromUrl(pdfurl,filesave);
iframepdf.Src = "~/DownloaddFiles/mypdffile.pdf";
}
public void DownLoadpdfFromUrl(string url, string savepath)
{
using (var client = new System.Net.WebClient())
{
client.DownloadFile(url, savepath);
}
}
}
Dowload Source Code
Result:
The post [Solved]-Download pdf file from link and save in local file folder in Asp .Net appeared first on Software Development | Programming Tutorials.
Read More Articles
- Write a value which contain comma to a CSV file in c#?
- Reading CSV File with cells containing commas c#
- Split CSV with columns may contain ‘,’ Comma C#
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- [Simple Way]-ASP.NET Core Upload Multiple File Web API model
- [Simple Way]- Image Upload in .NET Core Web API
- [Easy Way]-Receive File and other form data together in ASP.NET Core Web API
- Replace image in word document using C#
- How to add new rows to an existing word document table in C#
- to download a page as pdf file and save in a local folder in C#
- Download PDF file from Web location and Prompt user SaveAs box on client in web-Application ASP C#
- Download and save file from Amazon S3 with Unity C#
- How to download a zip file from link (ftp) and pass username and password?
- how to retrieve list of pdf files from ftp server's folder and shown it as .pdf link in aspx page?
- Download and save xml file on user local machine
- Download PDF File From DB to Local Server for Download
- Link to retrieve pdf file from DB- in asp.net
- Download a zip file from one folder location to another
- Download and delete file from Azure file shares
- Read multiple pdf attachments from Email & save all attachments as single pdf file
- How to save Zip file on local machine which is coming from HttpClient using SaveFileDialog in Windows application using C#?
- How to show FIleName and download link for file using ASP.Net MVC?
- Get file names from folder and sub-folders in C#
- How to download a file from a shared folder in asp.net using <a href>?
- download a file from server using a controller and javascript
- C#: Download large sized json file from ADLS gen2 blob and Deserialize to object
- Download a file to StreamingAssets folder using Unity and c#
- Open local html file from link in page loaded in WebBrowser
- Copy a .sav file from Appdata and place in a folder on desktop
- Generate Crystal Reports in loop and save in a zip file and download
- How to get data from two tables and save it in DTO in Net Core Entity Framework?
- after downloading files from url using c#.net and open that files in our local machine its is showing file corrupted
- Connect to local xml File and create button from results
- Send file from angular to create new and download from .net
- Download the latest excel file from the folder
- C# Coded UI - How to open a pdf file from a link in a web page
- C# Upload File to file.io and Get Download Link
- Xamarin.Mac OS X save and retrieve data from file
- Download PDF and Word file in UWP
- ActiveMQ 5.15.9 Security
- WPF Sliders and switches control Array
- Accessing Listbox Results View in C#
- Not creating background worker for a particular user
- after trigger click, the next delegate didnt work
- ddl index to Console.Writeline C# Selenium
- C# Selecting text in form1 from form2
- How to properly do Exception Handling with try and catch using C#
- ASP .NET MVC Data type for image
- Easiest way to achieve a simple one-to-many with a generic type using EF 4.1 code-first
- AutoMapper is not returning data from DataTable
- C# Saving to Access. Confusion
- How to check user input with if command
- Append dynamically created headers to div from c#
- Open Web Socket depend on current route C# asp net core
- C# sometimes the first command running after the second command
- Disable Multiline Textbox Resize Grip on Server Side
- Deserialize json response to multiple types dynamically using json.net
- C# created files only appear after the program stops
- Remove export Formats in devexpress Document Viewer tool in the Send Via Email Function