GetParentAsync method
Collapse the table of content
Expand the table of content

IStorageItem2.GetParentAsync method

Gets the parent folder of the current storage item.

Syntax


IAsyncOperation<StorageFolder> GetParentAsync()

Parameters

This method has no parameters.

Return value

Type: IAsyncOperation<StorageFolder>

When this method completes, it returns the parent folder as a StorageFolder.

Remarks

Important  
 
You must have access to the parent for the GetParentAsync method to succeed, either by declaring library capabilities or by persisting a higher-level folder in the Access List. Also, this method returns null if you can’t get to the parent, instead of raising an exception.

This example shows how to get the parent folder of a StorageFile.


function openParentFolder(file) {
    file.GetParentAsync().done(function (folder) {
        if (folder != null) {
            folder.getItemsAsync(function (items) {
                var list = document.getElementById("parentFolderItemsList");
                items.forEach(function (item) {
                    var listItemElement = document.createElement("li");
                    if (item.isOfType(Windows.Storage.StorageItemTypes.folder)) {
                        listItemElement.textContent = item.name + "\\";
                    } else {
                        listItemElement.textContent = item.name;
                    }
                    list.appendChild(listItemElement);
                });
            });
        } else {
            // Unable to get parent folder
        }
    });
}


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

None supported

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

IStorageItem2

 

 

Show:
© 2016 Microsoft