StandardDataFormats.StorageItems StandardDataFormats.StorageItems StandardDataFormats.StorageItems StandardDataFormats.StorageItems StandardDataFormats.StorageItems Property

Definition

A read-only property that returns the format ID string value corresponding to the StorageItem format.

public : static Platform::String StorageItems { get; }
static winrt::hstring StorageItems();
public static string StorageItems { get; }
Public Shared ReadOnly Property StorageItems As string
var string = Windows.ApplicationModel.DataTransfer.StandardDataFormats.storageItems;

Property Value

string string string

The format ID string value corresponding to the StorageItem format.

Examples

This example demonstrates the use of the StorageItems property. To use the code in this example, add an event listener to your app to handle the activated event. Then put this code in the function that this event listener calls.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;
using Windows.ApplicationModel.DataTransfer;
using Windows.Graphics.Imaging;

namespace ShareMainBetaCS
{
    public sealed partial class ShareFiles : Page
    {
        private StorageFile imageFile = null;
        private RandomAccessStreamReference imageStreamRef = null;
        private RandomAccessStreamReference dataPackageThumbnail = null;
        private IRandomAccessStream imageStream = null;

        public ShareFiles()
        {
            this.InitializeComponent();
            pickImageButton.Click += new RoutedEventHandler(pickImageButton_Click);
            this.ShareSourceLoad();
        }



        async void pickImageButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker imagePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
            };

            this.imageFile = await imagePicker.PickSingleFileAsync();

            if (this.imageFile != null)
            {
                this.imageStreamRef = RandomAccessStreamReference.CreateFromFile(this.imageFile);
                this.dataPackageThumbnail = this.imageStreamRef;
                this.imageStream = await this.imageFile.OpenAsync(FileAccessMode.Read);
            }

        }

        public void ShareSourceLoad()
        {
            DataTransferManager datatransferManager;
            datatransferManager = DataTransferManager.GetForCurrentView();
            datatransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
        }

        void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
        {
            e.Request.Data.Properties.Title = "Hello World!";
            e.Request.Data.Properties.Description = "This example shows how to use delayed sharing.";
            if (this.dataPackageThumbnail != null)
            {
                e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
            }
            e.Request.Data.SetDataProvider(StandardDataFormats.Bitmap, 
                    new DataProviderHandler(this.OnDeferredImageRequestedHandler));

        }
        async void OnDeferredImageRequestedHandler(DataProviderRequest request)
        {
            // Here we provide updated Bitmap data using delayed rendering
            if (this.imageStream != null)
            {
                DataProviderDeferral deferral = request.GetDeferral();

                try
                {
                    InMemoryRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();

                    // Decode the image
                    BitmapDecoder imageDecoder = await BitmapDecoder.CreateAsync(this.imageStream);

                    // Re-encode the image at 50% width and height
                    BitmapEncoder imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
                    imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
                    imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
                    await imageEncoder.FlushAsync();

                    request.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));
                }

                catch (Exception ex)
                {
                    // Handle the exception
                }

                finally
                {
                    deferral.Complete();
                }
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}
var imageFile;
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
picker.pickSingleFileAsync().then(function (file) {
    logText("PickImage: Picker returned a file");
    imageFile = file;
});

function onDeferredImageRequested(request) {
    try {
        if (imageFile) {
            // This is to make sure deferral works even in synchronous case
            var deferral = request.getDeferral();
            var imageStreamRef = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
            request.setData(imageStreamRef);
            deferral.complete();
        }
    } catch (exc) {
        // Error handling goes here.
    }
}


function shareFiles() {
    var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", function (e) {
        var request = e.request;
        request.data.properties.title = "Share Files Example";
        request.data.properties.description = "A demonstration that shows how to share files.";
        request.data.properties.fileTypes.replaceAll([".jpg", ".bmp", ".gif", ".png", ".wmv"]);
        request.data.setDataProvider(Windows.ApplicationModel.DataTransfer.StandardDataFormats.bitmap, onDeferredImageRequested);
    });
}