IStorageItem2
IStorageItem2
IStorageItem2
IStorageItem2
Interface
Definition
Manipulates storage items (files and folders) and their contents, and provides information about them.
Important
If you simply want to work with files and folders in your app, see the StorageFile and StorageFolder classes.
public : interface IStorageItem2public interface IStorageItem2Public Interface IStorageItem2// You can use this interface in JavaScript.
- Inheritance
-
IStorageItem2IStorageItem2IStorageItem2IStorageItem2
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Inherited Members
Inherited properties
Inherited methods
Methods
GetParentAsync() GetParentAsync() GetParentAsync() GetParentAsync()
Gets the parent folder of the current storage item.
public : IAsyncOperation<StorageFolder> GetParentAsync()public IAsyncOperation<StorageFolder> GetParentAsync()Public Function GetParentAsync() As IAsyncOperation( Of StorageFolder )// You can use this method in JavaScript.
When this method completes, it returns the parent folder as a StorageFolder.
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
}
});
}
IsEqual(IStorageItem) IsEqual(IStorageItem) IsEqual(IStorageItem) IsEqual(IStorageItem)
Indicates whether the current item is the same as the specified item.
public : PlatForm::Boolean IsEqual(IStorageItem item)public bool IsEqual(IStorageItem item)Public Function IsEqual(item As IStorageItem) As bool// You can use this method in JavaScript.
The IStorageItem object that represents a storage item to compare against.
Returns true if the current storage item is the same as the specified storage item; otherwise false.
Remarks
Use the IsEqual method to determine whether two storage items represent the same file or folder.
This method compares the Path property of both items to determine if they are the same. If there is no Path (if the item is a library for example), or if the paths do not match the items are compared using IShellItem::Compare.
This example shows how to compare two storage files for equality.
function openNewFile() {
var picker = new Windows.Storage.Pickers.FileOpenPicker;
picker.fileTypeFilter.replaceAll(["*"]);
picker.pickSingleFileAsync().then(function (file) {
var alreadyOpenedFile = null;
_openFiles.some(function (openFile) {
if (file.IsEqual(openFile.file)) {
alreadyOpenedFile = openFile;
return true;
}
return false;
});
if (alreadyOpenedFile != null) {
alreadyOpenedFile.window.activate();
} else {
createNewFileViewerWindow(file);
}
});
}