Dela via


IStorageItem2.GetParentAsync Method

Definition

Gets the parent folder of the current storage item.

public:
 IAsyncOperation<StorageFolder ^> ^ GetParentAsync();
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFolder> GetParentAsync();
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFolder> GetParentAsync();
function getParentAsync()
Public Function GetParentAsync () As IAsyncOperation(Of StorageFolder)

Returns

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

Attributes

Remarks

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
        }
    });
}

Applies to