Export (0) Print
Expand All

Document.getFilePropertiesAsync method (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

Gets file properties of the current document.

Last modified: June 12, 2014

Introduced in Office.js version

1.1

Available in requirement sets

Not in a set

Office.context.document.getFilePropertiesAsync([, options], callback);

options

Type: object

Specifies the following optional parameters.

asyncContext

Type: array, boolean, null, number, object, string, or undefined

A user-defined item of any type that is returned in the AsyncResult object without being altered. Optional.

callback

Type: function

A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. Optional.

When the function you passed to the callback parameter executes, it receives an AsyncResult object that you can access from the callback function's only parameter.

In the callback function passed to the getFilePropertiesAsync method, you can use the properties of the AsyncResult object to return the following information.

Property

Use to...

AsyncResult.value

Returns the file's URL to asyncResult.value.url

AsyncResult.status

Determine the success or failure of the operation.

AsyncResult.error

Access an Error object that provides error information if the operation failed.

AsyncResult.asyncContext

Access your user-defined object or value, if you passed one as the asyncContext parameter.

In this release of the API, you can only get the file's URL with the url property (asyncResult.value.url).

To read the URL of the current file, you need to write a callback function that returns the URL. The following example shows how to:

  • Pass an anonymous callback function that returns the value of the file's URL to the callback parameter of the getFilePropertiesAsync method.

  • Display the value on the app's page.

function getFileUrl() {
    //Get the URL of the current file.
    Office.context.document.getFilePropertiesAsync(function (asyncResult) {
        var fileUrl = asyncResult.value.url;
        if (fileUrl == "") {
            showMessage("The file hasn't been saved yet. Save the file and try again");
        }
        else {
            showMessage(fileUrl);
        }
    });
}

App types

Content apps, Task pane apps

Supported clients

Excel 2013, Excel 2013 SP1, Excel 2013 RT, Excel Online, Word 2013, Word 2013 SP1, Word 2013 RT, PowerPoint 2013, PowerPoint 2013 SP1, PowerPoint 2013 RT

Library

Office.js

Namespace

Office

Show:
© 2014 Microsoft