How to get thumbnail of Video Storage File in Windows phone app

StorageFile class provides us with the method called GetThumbnailAsync with the help of which we can retrieve the thumbnail of a storage file in Windows phone app.


Important Note:
This method works only on the Storage Files that are stored in public directory of the phone. It doesn’t work on the files that are present in app data container or Local Storage of the app.


So the method discussed below will be useful when you need to fetch all the video files that are stored in the gallery of phone or you are working on video files picked with FileOpenPicker method.


The code for fetching the thumbnail of video storage file is as following



If you need to save the thumbnail image to the Local Storage of your app you can use the following code given below



I hope this post will be helpful to you.


How to copy one StorageFile into another StorageFile in Windows phone app using C#

StorageFile class provides a method called CopyAsync to copy the contents of one file into another.

The code for the above is as following



Note: In the given code above we replace the contents of filetoReplace by filetoCopy.


If you want to copy the file to a given StorageFolder you can use the CopyAsync method. The code for the following is given below



Convert Storage File to Byte Array in Universal Windows apps

This async function converts a storage file to a byte array.

public static async Task<byte[]> GetBytesAsync(StorageFile file)
    byte[] fileBytes = null;
    if (file == null) return null;
    using (var stream = await file.OpenReadAsync())
        fileBytes = new byte[stream.Size];
        using (var reader = new DataReader(stream))
            await reader.LoadAsync((uint)stream.Size);
    return fileBytes;

It accepts a StorageFile as argument and returns a byte array for it.