Thursday, 24 June 2021

Retrieve And Display PDF File From App_Data Folder In Browser In Asp.net and C#.Net | How to Open PDF Files in Web Brower Using ASP.NET

6/24/2021 - By Pranav Singh 0

In this article I will show you how you can display PDF document present in App_Data folder in browser in your as asp.net application using C#.Net and VB.Net.

You May Also Like:

 How to Extract Text From PDF File Using C#.Net

Code to Export GridView to PDF in Asp.Net Using C# and Vb.Net


Suppose you have PDF file in you’re App_Data folder. Now follow the step to show the PDF file in your asp.net application.

Step 1:

In this step we will add PDF file in our App_Data folder.

App_data folder in asp.net

Step 2:

In this step we will add a new asp.net page on which we will display the App_Data folder.

Step 3:

Follow the below mention code to convert the PDF file into Byte array string.

     public void     PDFDisplay()

        {

            string fileFolderPath = "~/App_Data/professional-cloud-architect.pdf ";

            String file = Convert.ToBase64String(File.ReadAllBytes(Server.MapPath(fileFolderPath)));

            byte[] bytes = Convert.FromBase64String(bytePDF);

            Response.Clear();

            Response.ContentType = "application/pdf";

            Response.Buffer = true;

               Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.BinaryWrite(bytes);

            Response.End();

            Response.Close();

        }

 

Here in above code I have first stored the App_Data folder file path in a string variable and after that converted it into base64bit string.

Now through the Response.BinaryWrite function the PDF file file have been displayed on the screen. Now run the application and check the output.


How to Open PDF Files in Web Brower Using ASP.NET


You May Also Like:

 iTextSharp To Create PDF In C#

Export Html To PDF In Asp.Net C#

Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top