StorageLibrary StorageLibrary StorageLibrary StorageLibrary Class

Definition

Lets you add and remove folders from a library like Music or Videos and lets you get a list of folders included in the library.

public : sealed class StorageLibrary : IStorageLibrary, IStorageLibrary2, IStorageLibrary3
public sealed class StorageLibrary : IStorageLibrary, IStorageLibrary2, IStorageLibrary3
Public NotInheritable Class StorageLibrary Implements IStorageLibrary, IStorageLibrary2, IStorageLibrary3
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

You can only access libraries that you have declared capabilities for in your app manifest. To learn more about capabilities see, App capability declarations.

Properties

ChangeTracker ChangeTracker ChangeTracker ChangeTracker

Returns the StorageLibraryChangeTracker associated with the storage library.

public : StorageLibraryChangeTracker ChangeTracker { get; }
public StorageLibraryChangeTracker ChangeTracker { get; }
Public ReadOnly Property ChangeTracker As StorageLibraryChangeTracker
var storageLibraryChangeTracker = storageLibrary.changeTracker;
Additional features and requirements
Device family
Windows 10 Anniversary Edition (introduced v10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v3)

Folders Folders Folders Folders

Gets the folders in the current library.

public : IObservableVector<StorageFolder> Folders { get; }
public IObservableVector<StorageFolder> Folders { get; }
Public ReadOnly Property Folders As IObservableVector<StorageFolder>
var iObservableVector = storageLibrary.folders;
See Also

SaveFolder SaveFolder SaveFolder SaveFolder

Get the default save folder for the current library.

public : StorageFolder SaveFolder { get; }
public StorageFolder SaveFolder { get; }
Public ReadOnly Property SaveFolder As StorageFolder
var storageFolder = storageLibrary.saveFolder;
Value
StorageFolder StorageFolder StorageFolder StorageFolder

The default save folder for the current library.

Methods

AreFolderSuggestionsAvailableAsync() AreFolderSuggestionsAvailableAsync() AreFolderSuggestionsAvailableAsync() AreFolderSuggestionsAvailableAsync()

Determines if there are suggestions for adding existing folders with content to the StorageLibrary.

public : IAsyncOperation<Platform::Boolean> AreFolderSuggestionsAvailableAsync()
public IAsyncOperation<bool> AreFolderSuggestionsAvailableAsync()
Public Function AreFolderSuggestionsAvailableAsync() As IAsyncOperation( Of bool )
Windows.Storage.StorageLibrary.areFolderSuggestionsAvailableAsync().done( /* Your success and error handlers */ );
Returns

True if there are folder suggestions; False otherwise

Additional features and requirements
Device family
Windows 10 Fall Creators Update (introduced v10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Examples

This example demonstrates how to determine whether there are any suggested folders with content that can be added to your Pictures library.

private async Task<StorageLibrary> SetupPicturesLibraryAsync()
{
    if (this.picturesLibrary == null)
    {
        this.picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
        this.picturesLibrary.DefinitionChanged += PicturesLibrary_DefinitionChanged;
    }
    return this.picturesLibrary;
}

private async void CheckForFolderSuggestions_Clicked(object sender, RoutedEventArgs e)
{
    var library = await SetupPicturesLibraryAsync();

    if (await library.AreFolderSuggestionsAvailableAsync())
    {
        // There are new folders that could be added to the library.
        // Prompt the user to add one or more of them. 

        // Note that the RequestAddFolderAsync method returns only one folder.
        // If the user adds multiple folders, only one will be returned.
        // In this example, to keep track of all the added folders, the app can subscribe to the
        // StorageLibrary.DefinitionChanged event by awaiting library.RequestAddFolderAsync();

        // Launch the folder suggestion dialog
        var folder = await library.RequestAddFolderAsync(); 
    }
}

private void PicturesLibrary_DefinitionChanged(StorageLibrary sender, object args)
{
    foreach (StorageFolder folder in sender.Folders)
    {
        // Do something with every folder in the library
    }
}

Note

Don't forget to include the picturesLibrary capability in your app's package manifest. For more information on Capabilities in the manifest, see App capability declarations.

Remarks

If this feature is not supported on your version of Windows, the method will return false.

GetLibraryAsync(KnownLibraryId) GetLibraryAsync(KnownLibraryId) GetLibraryAsync(KnownLibraryId) GetLibraryAsync(KnownLibraryId)

Gets the specified library.

public : static IAsyncOperation<StorageLibrary> GetLibraryAsync(KnownLibraryId libraryId)
public static IAsyncOperation<StorageLibrary> GetLibraryAsync(KnownLibraryId libraryId)
Public Static Function GetLibraryAsync(libraryId As KnownLibraryId) As IAsyncOperation( Of StorageLibrary )
Windows.Storage.StorageLibrary.getLibraryAsync(libraryId).done( /* Your success and error handlers */ );
Parameters
libraryId
KnownLibraryId KnownLibraryId KnownLibraryId KnownLibraryId

A KnownLibraryId value that identifies the library to retrieve, like Music or Videos.

Returns
See Also

GetLibraryForUserAsync(User, KnownLibraryId) GetLibraryForUserAsync(User, KnownLibraryId) GetLibraryForUserAsync(User, KnownLibraryId) GetLibraryForUserAsync(User, KnownLibraryId)

Gets the specified library for a User.

public : static IAsyncOperation<StorageLibrary> GetLibraryForUserAsync(User user, KnownLibraryId libraryId)
public static IAsyncOperation<StorageLibrary> GetLibraryForUserAsync(User user, KnownLibraryId libraryId)
Public Static Function GetLibraryForUserAsync(user As User, libraryId As KnownLibraryId) As IAsyncOperation( Of StorageLibrary )
Windows.Storage.StorageLibrary.getLibraryForUserAsync(user, libraryId).done( /* Your success and error handlers */ );
Parameters
user
User User User User

The User for which the library is retrieved.

libraryId
KnownLibraryId KnownLibraryId KnownLibraryId KnownLibraryId

A KnownLibraryId value that identifies the library to retrieve, like Music or Videos.

Returns
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)
See Also

RequestAddFolderAsync() RequestAddFolderAsync() RequestAddFolderAsync() RequestAddFolderAsync()

Prompts the user to select a folder, and then adds the folder to the library.

public : IAsyncOperation<StorageFolder> RequestAddFolderAsync()
public IAsyncOperation<StorageFolder> RequestAddFolderAsync()
Public Function RequestAddFolderAsync() As IAsyncOperation( Of StorageFolder )
Windows.Storage.StorageLibrary.requestAddFolderAsync().done( /* Your success and error handlers */ );
Returns

When this method completes, it returns the folder that the user picked and added as a StorageFolder. If the user cancels the operation and doesn't pick a folder, the method returns null.

Remarks

The file picker displayed lets user select only library-eligible locations. If there are pending suggestions a suggestion dialog will be shown instead of a folder picker.

See Also

RequestRemoveFolderAsync(StorageFolder) RequestRemoveFolderAsync(StorageFolder) RequestRemoveFolderAsync(StorageFolder) RequestRemoveFolderAsync(StorageFolder)

Prompts the user to confirm removal of the specified folder from the current library, and then removes the folder.

public : IAsyncOperation<Platform::Boolean> RequestRemoveFolderAsync(StorageFolder folder)
public IAsyncOperation<bool> RequestRemoveFolderAsync(StorageFolder folder)
Public Function RequestRemoveFolderAsync(folder As StorageFolder) As IAsyncOperation( Of bool )
Windows.Storage.StorageLibrary.requestRemoveFolderAsync(folder).done( /* Your success and error handlers */ );
Parameters
Returns

Returns true if the folder was removed; otherwise false.

Remarks

Important

This method must be called from a UI thread.

See Also

Events

DefinitionChanged DefinitionChanged DefinitionChanged DefinitionChanged

Occurs when the list of folders in the current library changes.

public : event TypedEventHandler DefinitionChanged<StorageLibrary, object>
public event TypedEventHandler DefinitionChanged<StorageLibrary, object>
Public Event TypedEventHandler DefinitionChanged( Of ( Of StorageLibrary ), ( Of object ))
function onDefinitionChanged(eventArgs){/* Your code */}


storageLibrary.addEventListener("definitionChanged", onDefinitionChanged);
storageLibrary.removeEventListener("definitionChanged", onDefinitionChanged);