Tell me more ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I am creating a web application where I would be downloading word (.doc) file from database. What my client wan't is once I click the "Open File A" button/ link, it should download word file automatically (at some path) and get it open in MS Word. My client don't want users to download the file and double click on it and open.

Can we do it?

For web application, below are the technologies I am using.

  1. Glassfish server
  2. JSF 2.0
  3. Java
  4. MySQL

I believe, in web application, we can't have access over client machine so we can't open the file using MS Word. What we can achieve is download the file at path provided by user. Please suggest me if I am wrong.

Any idea would be greatly appreciated.

Note: Using Java, I tried using Desktop class, however this would run on webserver which is not client machine, so it won't help me.

Update 1

In simple way, I have a button called "Open File A" on web-browser. When I click on it, it should do below steps.

  1. Download that file from DB (say abc.doc).
  2. Open this file in Microsoft Office Word (By Browser and not by person)

I am able to do first part, concern is second part.

share|improve this question
1  
Web Applications Q&A is for end users of webapplications, questions on development/programming would be offtopic – Sathya Aug 15 '12 at 14:26
@Sathya : If its offtopic, where should I ask this question? – Fahim Parkar Aug 16 '12 at 6:56
@FahimParkar at Stack Overflow – thekirbylover Aug 16 '12 at 7:10

closed as off topic by Alex, Al Everett, Sathya, ChrisF Aug 15 '12 at 15:06

Questions on Web Applications Stack Exchange are expected to relate to web applications within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

As far as I know, automatically opening Office documents can only be done in Internet Explorer: I use a SharePoint site which, when used in IE, only requires a simple security warning to be confirmed before immediately opening a document in Word. Unfortunately, I'm not sure of what code it uses. I'll have a look now and update this answer if I find out. It seems to be using VBScript to create an ActiveX object:

<script type="text/vbscript">
On Error Resume Next
Set opener = CreateObject("SharePoint.OpenDocuments.3")
If Not IsObject(opener) Then
    Set opener = CreateObject("SharePoint.OpenDocuments.2")
    If Not IsObject(opener) Then
        Set opener = CreateObject("SharePoint.OpenDocuments.1")
        If Not IsObject(opener) Then
            ' the feature isn't available; the file will need to be downloaded like normal
        End If
    End If
End If
</script>

Now you can use its ViewDocument function, which simply takes the file's URL as an argument. Here's a function that attempts to open the file in its appropriate Office app and falls back to the normal download method if that doesn't work:

// (JavaScript)
function openDocument(url) {
    try {
        opener.ViewDocument(url);
    } catch (error) {
        location = url;
    }
}
share|improve this answer
ok fine... I will wait for updated answer – Fahim Parkar Aug 15 '12 at 13:04
I don't want to open doc file in web browser. I want web browser to open doc file in MS WORD. – Fahim Parkar Aug 15 '12 at 13:05
Yes, that's what I meant – thekirbylover Aug 15 '12 at 13:18
ok. did you found the code? – Fahim Parkar Aug 15 '12 at 13:41
Yep, just updating the answer now – thekirbylover Aug 15 '12 at 14:36
show 3 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.