Create, update, read, or delete albums (Windows Runtime apps using C#/VB and XAML)

Your apps can use the Live SDK to create, read, update, and delete a Microsoft OneDrive user's albums. An album on OneDrive is a special type of folder that can store photos, videos, audio, as well as child albums and child folders.

In this article
Prerequisites
Create an album
Update an album
Read an album
Delete an album
Remarks

Prerequisites

We assume that the user has already signed in and consented to the wl.skydrive scope for reading file or folder properties. If you have not added user sign-in to your Windows Runtime apps, see Signing users in (XAML).

Create an album

To add a new album, use code like this. The wl.skydrive_update scope is required.

Note

You can create albums only in the user's top-level OneDrive folder, represented here as me/albums.

private async void btnCreateAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var albumData = new Dictionary<string, object>();
        albumData.Add("name", "A brand new album");
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.PostAsync("me/albums", albumData);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Created album:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error creating album: " + exception.Message;
    }
}

Update an album

To change info for an existing album, use code like this. The wl.skydrive_update scope is required.

private async void btnUpdateAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        var albumData = new Dictionary<string, object>();
        albumData.Add("name", "Nature Photography 2");
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.PostAsync("folder.8c8ce076ca27823f.8C8CE076CA27823F!134", albumData);
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = "Album updated:" + result.name;
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error updating album: " + exception.Message;
    }
}

Read an album

To get info about an album, you can use code like this. The wl.photos or wl.skydrive scope is required.

To use this code, change the album ID to this:

  • A different album ID, to get info about another album.

  • me/albums, to get info about all of the signed-in user's albums.

  • /me/skydrive/shared/albums, to get info about all of the signed-in user's shared albums.

  • USER_ID/albums, to get info about all of a user's albums that correspond to a valid USER_ID.

private async void btnReadAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.GetAsync("folder.8c8ce076ca27823f.8C8CE076CA27823F!134");
        dynamic result = operationResult.Result;
        this.infoTextBlock.Text = string.Join(" ", "Album name:", result.name, "ID:", result.id);
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error getting album info: " + exception.Message;
    }
}

You can also do this:

  • Use ALBUM_ID/photos or ALBUM_ID/videos, to get a list of all photos or videos in an album. Then your code can make another call that uses a specific photo ID or video ID to get the info for that photo or video.

  • Use ALBUM_ID/files to get a list of all photos, videos, audio, child albums, and child folders in an album. Then your code can make another call that uses a specific photo ID, video ID, album ID, audio ID, or folder ID to get the info for that photo, video, album, audio, or folder.

    Note

    You can get info about an album's photos, videos, audio, child albums, and child folders only.

  • Use ALBUM_ID/picture to get a picture of an album's cover.

  • Get a limited number of items by using the limit parameter in the preceding code to specify the number of items to get. For example, to get the first two items, use ALBUM_ID/files?limit=2.

  • Set the first item to start getting by using the offset parameter in the preceding code to specify the index of the first item to get. For example, to get two items starting at the third item, use ALBUM_ID/files?limit=2&offset=3.

    Note

    In the JavaScript Object Notation (JSON)-formatted object that's returned, you can look in the paging object for the previous and next structures to get the offset and limit parameter values of the previous and next entries.

  • Set the items' sort criteria by using the sort_by parameter in the preceding code to specify the criteria: updated, name, size, or default. For example, to sort the items by name, use ALBUM_ID/files?sort_by=name.

  • Set the items' sort order by using the sort_order parameter in the preceding code to specify the order: ascending or descending. For example, to sort the items in descending order, use ALBUM_ID/files?sort_by=descending.

Delete an album

To remove an album, use code like this. The wl.skydrive_update scope is required. Change the album ID to the album ID of the album that you want to remove

private async void btnDeleteAlbum_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveConnectClient liveClient = new LiveConnectClient(this.session);
        LiveOperationResult operationResult =
            await liveClient.DeleteAsync("folder.a6b2a7e8f2515e5e.A6B2A7E8F2515E5E!148");
        this.infoTextBlock.Text = "Album deleted.";
    }
    catch (LiveConnectException exception)
    {
        this.infoTextBlock.Text = "Error deleting album: " + exception.Message;
    }
}

Remarks

For details about the minimum required and optional structures that your app must provide when using PUT or POST, see the Album object.