Monday, April 7, 2008

How to Show Binary Files in the Browser using ASP.NET and VB.NET

This article explains how to show binary files as well as .doc .xls files in browser. We have seen in many sites that user can open .gif, .jpg, .doc and .xls files by clicking a link. The binary format file as well as .doc .xls is displayed in the browser
1)Create an asp.net web project. Name the project as ShowBinary
2) Add a file of type (.gif,.jpg,.doc,.xls) to the project
3) Specify a Start page for the application4) Use following code snippet in the form load event handler

Private Sub Page_Load(sender as object, e as System.EventArgs)
Response.ContentType = “Application/pdf” ‘ Specify Content Type
Dim fpath as string = Mappath(“Mypdf.pdf”) ‘ Specify Physical Path of the file
Response.writefile(fpath)
End Sub