user1502429
user1502429

Reputation: 13

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();

Upvotes: 1

Views: 8374

Answers (4)

Med.Amine.Touil
Med.Amine.Touil

Reputation: 1235

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

Upvotes: 0

user1502429
user1502429

Reputation: 13

<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>

Upvotes: 0

ilivewithian
ilivewithian

Reputation: 19692

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.

Upvotes: 0

John Saunders
John Saunders

Reputation: 161773

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.

Upvotes: 2

Related Questions