asp.net online editing word documents can be saved to the server

  • 2020-05-07 19:32:42
  • OfStack

Note: the word document you want to open on the server side must have write permission. iis is allowed to open webdav in the web service extension

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

How it works: by creating an ActiveX control instance on javascript (Program Files\Microsoft \OFFICE11\ owssupp.dll or Program Files\Microsoft \ Office\OFFICE10\ owssupp.dll), you can activate the 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, the corresponding method of openDocObj is called. For example, open one 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 in the parameters (.doc,.xls,.ppt). The ViewDocument() method also has an overloaded signature that lets us manually specify which program to activate to open the document:

openDocObj. ViewDocument (" http: / / www. abc. com/documents/sample doc ", in order to activate the program ProgID);

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

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

You can directly activate Word, edit the document in Word, and then directly click the save function in Word, you can save the file to the server. Note: in order to let Word document after editing can be directly will save server, access to the current context Web site Windows Identity must be corresponding to the server directory (i.e., "http: / / www. abc. com/documents" the physical path of the virtual directory server) have corresponding write permissions, or save the action will fail. When the edit is complete, EditDocument() returns an bool value to reflect whether the edit was successful.

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" this template to create a new document, the default new document preservation site is "http: / / www. abc. com/documents/". The program used to create a new document depends on the type of template file (for example, the.dot template will correspond to Word). Saving new documents also requires attention to permissions. The CreateNewDocument() method also returns an bool value to indicate whether the operation was successful.

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


Related articles: