1

I would like to load/save a file directly from the local filesystem in Word online (without uploading it to onedrive). Since this is not part of the default functionality I am trying to determine if this would be possible with an addin.

The loading part:

The Document object gives access to body load and save Methods however the documentation is unclear (to me) for load:Fills the proxy object created in JavaScript layer with property and object values specified in the parameter.

It seems there are options available like insertFileFromBase64 and insertOoxml but unclear if those are only in (Windows) Desktop version or also in Online version. See this question

The saving part:

This seems to be the easier bit as there already is a Download functionality to get a copy of the document.

Not looking for complete solution, just a "is it possible" and perhaps a few pointers to what methods to use.

Community
  • 1
  • 1
Remko
  • 7,214
  • 2
  • 32
  • 52

1 Answers1

1

probably I am doing many assumptions with my answer, please correct me if I am wrong but I think what you want to do is a WORD Add-in (a task pane add-in) that exposes the following functionalities:

  1. Uploads the current document - to OneDrive for Business (basically what you are calling "Office Online" or whatever other cloud repository.
  2. Connects to OneDrive or any cloud repository and opens, enables the user to select a word File and open it, either on the current document or a new one.

and if those 2 assumptions are correct, i think you can actually build an add-in with such functionalities. BTW note that within the Word experience you can actually save and load Word files from OneDrive, so i am not sure i understand what you mean by "this is not part of the default functionality" .

Anyways here is what you can do with API:

  1. You can get the current file, either the docx, pdf or txt equivalents, for this you need to use the getFileAsync method. This method gives you the file encoded as base64 and you can then upload it wherever you need. you can slice the file as well if needed. Here is a good example on how to use the API.
  2. To open a file in the current document. For this, effectively, you need to use the document.body.insertFileFromBase64 method. This method works in Word for Windows, Online, Mac and iOS. Check out a sample here.
    1. Finally there is a PREVIEW api you can try to actually open the document in a different window. Check out the exercise #8 on this lab. Using the createDocument functionality. (note that you need to use the preview APIs as described here).

Now in order to connect to OneDrive and upload or get files as well as navigating the folder structure you need to use the graph API against one drive. Here is a good example on how to authenticate and make calls to the graph.

I know this is a bunch of information but should put you in the right direction.

Thanks and HAPPY CODING!

Juan Balmori
  • 4,898
  • 1
  • 8
  • 17
  • Thanks a lot for your answer Juan, I may have done a poor job in explaining what I would like as uploading to onedrive as exactly what I'd like to avoid. So my goal is to open a local file (eg from documents) folder and download it when finished. (I will update my question to make this more clear) – Remko Oct 07 '16 at 19:33
  • 1
    Thanks for the clarification. Right now the JavaScript API for Word can only be used from within an Add-in (basically a task pane inserted in the document) I will fwd your message to someone in our Graph team to validate the feasibility if this. thanks! – Juan Balmori Oct 07 '16 at 19:44
  • got an answer from our Graph team. This is doable you would need to To do this, you would need to: 1) Use Microsoft Graph to upload the file from the local file system to the user’s OneDrive. 2) Use OneDrive to return the webUrl for the document, which will open the WAC experience for the file. 3) Wait for the user to be done. 4) Download the changed document (assuming changes were made) and replace the local file. Hope this helps/sets you up in the right direction. – Juan Balmori Oct 17 '16 at 17:26