Opening Word Document on Client Side from Asp.net Application

We need to open a word document which is located on a server on the clients machine using Microsoft Word. The solution is working locally however when deployed on server then only thing that happens is that the winword.exe is started on the server. Is this possible to do using interop or javascript?

this is the code till now

Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

object file = FilePath + FileName;
lblError.Text = lblError.Text + file.ToString(); 
object readOnly = false;
object objTrue = true;
object missing = System.Reflection.Missing.Value;
object emptyData = string.Empty;
wordApp.Visible = true;
Microsoft.Office.Interop.Word.Document aDoc                         =
wordApp.Documents.Open(ref file,
         ref missing, ref readOnly,
         ref missing, ref missing, ref missing,
         ref missing, ref missing, ref missing,
         ref missing, ref missing, ref objTrue);

aDoc.Activate();

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You have to keep in mind that the client and server are running on two different machines. The server can’t start a program running on the client machine.

Also, FYI, never use Office Automation from an ASP.NET application. Those APIs were designed for use in a desktop application. They won’t work properly, are unsupported, and may even violate your Office license.

Method 2

The reason it is working locally, is because, well, it isn’t. What’s happening is that the server is opening the document, but because your local machine is acting as the server it appears as if the file is opened.

One simple solution is for the user to download the file, edit it and upload it back to you.

Method 3

<script language="javascript" type="text/javascript"> 
    function openDokument(dokument){ 
        var objAppl;

        try{ 
            objAppl = GetObject("","Word.Application"); 
            objAppl.Documents.open(dokument); 
        } 
        catch(exception){ 
            objAppl = new ActiveXObject("Word.Application");
            objAppl.Visible = true;
            alert(dokument);
            objAppl.Documents.open(dokument);
            objAppl.Activate(); 
        }    
        objAppl = null;           
    }
</script>

Method 4

You can use the DocX class to create your word doxument. Then the Response.Write() method (precise that the doxument extension is .docx) to download the document in your machine


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x