Open word/excell file in client.

Posted on 2007-07-20
Last Modified: 2008-01-09
Hi everyone, i'm trying something that i don't know if it's possible:

I've got a tomcat server in a linux system and i'm trying to open a file in the client machine.

The idea is, he clicks a button and, say and excell file or word file opens up. (or whatever file opens whatever program that it's extension is associated with in the client machine).

is this possible? what code should i use.? jsp or javascript is fine by me.
Question by:ogog
    LVL 17

    Expert Comment

    You should just need to navigate the browser to the file and the mime types should take over from there.

    browsing to a .doc file should open in Microsoft Word, if the user has the appropriate application installed, and that application is set to be the default to open that type of document.

    This is the behavior of the browser and the operation system.

    so you could navigate to it through javascript or just use an anchor tag that points to the document. The browser should open the document in the correct application.

    you can force or try to force a browser to open in a particular application by changing the mime-type of your webpage. So if you had a webpage called test.asp you could make it open with Excel if the user has Excel installed by doing the following at the very beginning of the page even before the html tag

    <%@ Language=VBScript %>
       'Change HTML header to specify Excel's MIME content type
       Response.Buffer = TRUE
       Response.ContentType = "application/"
    LVL 17

    Accepted Solution

    Note, if you are trying to open a file that exists on the local users hard disk somewhere, you will need to know the path of the file on the disk and instead of as the href you would use
    the acutal path to the document ie... c:\documents and settings\usename\desktop\blah.doc

    LVL 1

    Author Comment

    i'll try that and report back points in about 3 days.

    thank you very much!
    LVL 54

    Expert Comment

    Why did you accept that comment as the answer?  Did you try it?  Did it work for you?  Where was this page located (i.e. Internet site, intranet, local machine)?

    That comment will not work in an Internet page.  The browser doesn't allow access to local file even if you know the path.  There are a few exceptions in non-Internet uses but they are browser specific and rare.  Please reply to let us know that you didn't just accept a comment.  In most cases that "answer" is wrong.

    LVL 1

    Author Comment

    i don't have pleasure in accepting wrong answers, obviously it did work. the file is local.

    the answer was simple and effective to what i looked for, otherwise i would have not reated it Ecellent.

    i forgot to accept it sooner because it worked! if it didn't i would have post a comment faster.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now