Opening Word Document on Client Side from Asp.net Application

依然范特西╮ 提交于 2019-12-02 02:51:19

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.

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!