Click here to Skip to main content
15,937,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to code in that when ever user clicks on link which redirects to file say "sample.doc" ,that file has to be opened in the browser.I am able to open in the separate window.MY intention is to open in the Browser itself

It just like how we are able to view any type of document in the gmail's attachment
Sandeep Mewara 29-Apr-11 3:24am    
Any effort?

Try this link..
hope it can help
Share this answer
Hi Prasad,

it all depends on what type of RESPONSE you send to user. The response includes some header details on type of data being sent and the data itself, the browser then, reads the information an takes action accordingly.

For example:
Dim stream As New MemoryStream
   document.Save(stream, False)
        Response.ContentType = "application/excel"
        Response.AddHeader("content-length", stream.Length.ToString())

The above code says the data being passed is type of excel application. then browser asks the OS for application like excel or if any extension is given the browser asks for the application with which extension is registered and open it in that application.

So you need to send proper header information with data for what you want to achieve.

try adding following statement:
Response.AppendHeader("Content-Disposition", "inline;filename=" + "ExcelFile.xls")

If you have a working example like google, you can check what exactly google is sending to your browser to open the file. You can use Fiddler to see what all requests the browser is sending for google and what is the response it is getting. The same settings you can use for your purpose.

Hope this will help.

Share this answer
Prasad Avunoori 4-May-11 3:12am    
i am able to view pdf,jpg files but not msoffice files how can i achieve it?
Prasad Avunoori 9-Jun-11 8:58am    
The code snippet which you mentioned above is useful to open the document in the Msword application but not in the Browser .

could you help me in Edit and view the office document in the browser.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900