Asp.net online Word documents can be saved to the server

Source: Internet
Author: User

Note: You must have the write permission for the server-side Word documents you want to open. To enable iis, the webdav in the web service extension is allowed.

Msdn: http://msdn2.microsoft.com/en-us/library/ms454230.aspx

Principle: Create an ActiveX control instance through javascript (for the browser machine Program Files \ Microsoft Office \ OFFICE11 \ owssupp. dll or Program Files \ Microsoft Office \ OFFICE10 \ owssupp. dll) to activate the local Office software to open and edit Office documents.

First, use a Script to create a local object:

OpenDocObj = new ActiveXObject ("SharePoint. OpenDocuments.2"); // to be compatible with Office XP, you can create "SharePoint. OpenDocuments.1"

Then, call the corresponding method of openDocObj. For example, open an Office document on the server:

OpenDocObj. ViewDocument ("http://www.abc.com/documents/sample.doc ");

The opendocobjobject uses different officedocument (.doc).xls0000.ppt) to open different programs (Word, Excel, and PowerPoint ). The ViewDocument () method also has an overload signature, which allows us to manually specify which program to activate to open the document:

OpenDocObj. ViewDocument ("http://www.abc.com/documents/sample.doc", ProgID of the program to be activated );

If you want to open the Office program to edit the file online and save it to the server, you can write as follows:

OpenDocObj. EditDocument ("http://www.abc.com/documents/sample.doc ");

You can directly activate Word, edit the document in Word, and then click Save in Word to save the file to the server. Note: To enable Word to directly Save the edited document to the server, the Windows Identity that accesses the current context of the Web site must have the write permission on the server's corresponding directory (that is, the physical path on the server corresponding to the virtual directory "http://www.abc.com/documents, otherwise, the SAVE action fails. After editing, EditDocument () returns a bool value to indicate whether the editing operation is successful.

We can also open a document template on the server to create a new document:

OpenDocObj. CreateNewDocument ("http://www.abc.com/documents/sampleTemplate.dot", "http://www.abc.com/documents ");

You can use the "http://www.abc.com/documents/sampleTemplate.dot" template to create a new document. By default, the new document is saved in "http://www.abc.com/documents ". The program used to create a new document depends on the template file type (for example, the. dot template corresponds to the Word ). You also need to pay attention to permissions when saving new documents. The CreateNewDocument () method returns a bool value to indicate whether the operation is successful.

The first parameter of the CreateNewDocument () method, in addition to using a template address, can also be directly specified as the ProgID of the client program to create a new document.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.