Opening Word in Browser

I have a link when clicked should open the word document in browser. here i am getting open and save option but my requirement is the file should be opened directly in the browser without asking user to save or open. please help
aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="TrainingCenter_test" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton></div>
    </form>
</body>
</html>
 
 
code file 
using System.IO;
 
public partial class TrainingCenter_test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string path = "123.doc";
        string fname = "123";
 
        string strPath = Server.MapPath("..\\Head_Office_Content" + "\\" + path);
 
        if (File.Exists(strPath))
        {
           Page.RegisterStartupScript("k", "<Script>window.open('" + "../Head_Office_Content/" + fname + ".doc" + "','" + fname + "','maximize=true,top=0,resizable=0,left=0,Width=1010px,Height=680px,status=0,toolbar=0,menubar=0,fullscreen=0, scrollbars=yes, location=0');</Script>");
        }
        else
        {
            Response.Write("File not found");
        }
    }
}

Open in new window

mannevenuAsked:
Who is Participating?
 
GiftsonDJohnCommented:
0
 
sybeCommented:
It is a client setting, something in the registry of the client. There is nothing you can do with your code on the server.
0
 
mannevenuAuthor Commented:
ooppss
but can I take the file contents and display in browser using Response.write();
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
sybeCommented:
It isn't easy to take the file contents of a Word document, but in theory it is possible.
0
 
mannevenuAuthor Commented:
hmmmm can u help me
in theory it is possible?i dint get u? how can i do that
0
 
GiftsonDJohnCommented:
Hi,

It is a security settings from Internet Explorer by default it will prompt whether to open or save the file. This is to prevent from downloading any harmful attachments.

If you really want to prevent the dialog you can use the following link. This settings has to be done on every client's machine.

http://www.mydigitallife.info/2007/06/15/disable-automatic-opening-or-saving-of-downloads-re-enable-always-ask-before-check-box/
0
 
GiftsonDJohnCommented:
If you want to read the contents from word and display in browser, you can use the following 3rd party component.

http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx
0
 
mannevenuAuthor Commented:
well this is not my requirement, well ok can i open atleast text file in browser using asp.net?
0
 
mannevenuAuthor Commented:
ok i will check this
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.