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.
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.
You May Also Like:
0 comments:
Please let me know your view