asp.net online edit Word document to save to server _ practical tips

Source: Internet
Author: User

Note: You want to open the server side of the Word document to have write permission. IIS to open a WebDAV in the Web service extension to allow

Specific reference Documentation msdn:http://msdn2.microsoft.com/en-us/library/ms454230.aspx

Rationale: Create an ActiveX control instance via JavaScript (for browser machine Program Files\Microsoft Office\office11\owssupp.dll or Program Files\Microsoft Office\office10\owssupp.dll) enables you to activate your local office software to open and edit Office documents

First, create a local object with script:

Opendocobj = new ActiveXObject ("Sharepoint.opendocuments.2"); To be compatible with Office XP, you can create "Sharepoint.opendocuments.1"

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

Opendocobj.viewdocument ("Http://www.abc.com/documents/sample.doc");

The Opendocobj object opens different programs (Word, Excel, PowerPoint) based on the different Office document types (. doc,. xls,. ppt) in the parameter. The ViewDocument () method also has an overloaded signature, which allows us to manually specify which program is activated to open the document:

Opendocobj.viewdocument ("Http://www.abc.com/documents/sample.doc", the ProgID of the program to be activated);

If you want to open an Office program to edit the file online and save it to the server you can write this:

Opendocobj.editdocument ("Http://www.abc.com/documents/sample.doc");

You can directly activate Word, edit the document in Word, and then directly click on the Save function in Word, you can save the file to the server. Note: In order for Word to save the edited document directly to the server, Windows identity that accesses the current context of the Web site must have a corresponding directory for the server (that is, "http://www.abc.com/documents" The physical path on the server for this virtual directory has the appropriate write permission, otherwise the Save action will fail. When the edit is complete, editdocument () returns a bool value to reflect the success of the edit operation.

We can also create a new document by opening a document template on the server:

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, where the default new document is saved as "http://www.abc.com/documents/." The program that you use when you create a new document depends on the type of template file (for example, the. dot template corresponds to Word). The preservation of new documents also requires attention to permissions issues. The CreateNewDocument () method also returns a bool value to reflect the success of the operation.

The first parameter of the CreateNewDocument () method, in addition to the address of one template, can be directly specified as the ProgID of the client program that you want to use 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.