StandardDataFormats StandardDataFormats StandardDataFormats StandardDataFormats Class

Contains static properties that return string values. Each string corresponds to a known format ID. Use this class to avoid errors in using string constants to specify data formats.

Syntax

Declaration

public static class StandardDataFormatspublic static class StandardDataFormatsPublic Static Class StandardDataFormats

Remarks

The DataPackage class supports several format types. Whenever you need to specify a format, we recommend using the properties of the StandardDataFormats class, instead of string values. Doing so ensures consistency between source and target applications.

The DataPackage class supports a number of legacy formats for interoperability between Windows Store app and desktop apps. To retrieve these formats, you pass one of the following strings to the GetDataAsync(System.String) method instead of a value from the StandardDataFormats class.

If format name is:GetDataAsync() retrieves:
"AnsiText"String for CF_TEXT.
"DeviceIndependentBitmap"Stream for HGLOBAL corresponding to CF_DIB.
"DeviceIndependentBitmapV5"Stream for HGLOBAL corresponding to CF_DIBV5.
"DataInterchangeFormat"Stream for HGLOBAL corresponding to CF_DIF.
"EnhancedMetafile"Stream for HENHMETAFILE corresponding to CF_ENHMETAFILE.
"Locale"Stream for HGLOBAL corresponding to CF_LOCALE
"OEMText"String for CF_OEMTEXT.
"PenData"Stream for HGLOBAL corresponding to CF_PENDATA
"RiffAudio"Stream for HGLOBAL corresponding to CF_RIFF.
"SymbolicLink"Stream for HGLOBAL corresponding to CF_SYLK.
"TaggedImageFileFormat"Stream for HGLOBAL corresponding to CF_TIFF.
"WaveAudio"Stream for HGLOBAL corresponding to CF_WAVE.

The Windows Runtime provides limited support for metafiles. Specifically, the Windows Runtime:

  • Supports rendering metafiles, but not creating them.
  • Supports the CF_ENHMETAFILE format ("EnhancedMetafile"), but not CF_METAFILEPICT.
  • Supports requesting data in "EnhancedMetafile" format, but not providing it; that is, calling SetData("EnhancedMetafile", <data>) won't work.
  • Provides limited support through the clipboard API for exchanging metafiles between Windows Store app and desktop apps.

Examples

This example shows how to retrieve shared text.

var shareOperation = eventObject.detail.shareOperation;
if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.text)) {
    shareOperation.data.getTextAsync().done(function (text) {
            // To output the text using this example, 
            // you need a div tag with an id of "output" in your HTML file.
            document.getElementById("output").innerText = text;
        }, function (e) {
            displayError("Error retrieving Text format: " + e);
        }
    });
}

Properties summary

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

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

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

A read-only property that returns the format ID string value corresponding to the Rich Text Format (RTF).

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

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

Note

Uri may be altered or unavailable for releases after Windows 8.1. Instead, use ApplicationLink or WebLink.

A read-only property that returns the format ID string value corresponding to the Uniform Resource Identifier (URI) format.

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

Properties

  • Bitmap
    Bitmap
    Bitmap
    Bitmap

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

    public static string Bitmap { get; }public static string Bitmap { get; }Public Static ReadOnly Property Bitmap As string

    Property Value

    • string
      string
      string
      string

      The format ID string value corresponding to the Bitmap format.

    Remarks

    Examples

    This example demonstrates the use of the Bitmap 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.

    void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
    {
        DataRequestDeferral deferral = e.Request.GetDeferral();
        e.Request.Data.Properties.Title = "Hello World!";
        e.Request.Data.Properties.Description = "This example shows how to share files and images.";
        if (this.dataPackageThumbnail != null)
        {
            e.Request.Data.Properties.Thumbnail = this.dataPackageThumbnail;
        }
        e.Request.Data.SetBitmap(imageStreamRef);
        deferral.Complete();
    }
    
    function registerForShare() {
        var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
        dataTransferManager.addEventListener("datarequested", shareImageHandler);
    }
    
    function shareImageHandler(e) {
        var request = e.request;
        request.data.properties.title = "Share Image Example";
        request.data.properties.description = "A demonstration that shows how to share an image.";
        var deferral = request.getDeferral();
        Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\smalllogo.png").then(function (thumbnailFile) {
            request.data.properties.thumbnail = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(thumbnailFile);
            return Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("images\\logo.png");
        }).done(function (imageFile) {
            request.data.setBitmap(Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile));
            deferral.complete();
        }, function (err) {
            request.failWithDisplayText(err);
        });
    }
    
  • Html
    Html
    Html
    Html

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

    public static string Html { get; }public static string Html { get; }Public Static ReadOnly Property Html As string

    Property Value

    • string
      string
      string
      string

      The format ID string value corresponding to the HTML format.

    Remarks

    Examples

    This example demonstrates the use of the Html 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.

    public void ShareSourceLoad()
    {
        DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
        dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
    }
    
    async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
    {
        string htmlExample = "<p>Here is our store logo: <img src='assets/logo.png'>.</p>";
        string fileExample = "assets\\logo.png";
        RandomAccessStreamReference streamRef = null;
        Windows.Storage.StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileExample);
        try
        {
            streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
        }
        catch (Exception ex)
        {
            // TODO: Handle the exception.
        }
        string htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(htmlExample);
        DataRequest request = e.Request;
        request.Data.Properties.Title = "Share HTML Example";
        request.Data.Properties.Description = "An example of how to share HTML.";
        request.Data.SetHtmlFormat(htmlFormat);
        request.Data.ResourceMap[fileExample] = streamRef;
    }
    
    function shareHtmlHandler(e) {
        var request = e.request;
        var htmlExample = "<p>Here is our store logo: <img src='images/logo.png'>.</p>";
        var localImage = "images\\logo.png";
        request.data.properties.title = "Share Html Example";
        request.data.properties.description = "A demonstration that shows how to share an HTML fragment with a local image.";
        var deferral = e.request.getDeferral();
        Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(localImage).done(function (imageFile) {
            request.data.setHtmlFormat(Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(htmlExample));
            request.data.resourceMap[localImage] = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imageFile);
            deferral.complete();
        }, function (err) {
            request.failWithDisplayText(err);
        });
    }
    
  • Rtf
    Rtf
    Rtf
    Rtf

    A read-only property that returns the format ID string value corresponding to the Rich Text Format (RTF).

    public static string Rtf { get; }public static string Rtf { get; }Public Static ReadOnly Property Rtf As string

    Property Value

    • string
      string
      string
      string

      The format ID string value corresponding to the Rich Text Format (RTF) format.

  • StorageItems
    StorageItems
    StorageItems
    StorageItems

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

    public static string StorageItems { get; }public static string StorageItems { get; }Public Static ReadOnly Property StorageItems As string

    Property Value

    • string
      string
      string
      string

      The format ID string value corresponding to the StorageItem format.

    Remarks

    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);
        });
    }
    
    
  • Text
    Text
    Text
    Text

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

    public static string Text { get; }public static string Text { get; }Public Static ReadOnly Property Text As string

    Property Value

    • string
      string
      string
      string

      The format ID string value corresponding to the Text format.

    Remarks

    Examples

    This example demonstrates the use of the Text 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.

    //To see this code in action, add a call to ShareSouceLoad to your constructor or other
    //initializing function.
    private void ShareSourceLoad()
    {
        DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
        dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
    }
    
    private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
    {
        DataRequest request = e.Request;
        request.Data.Properties.Title = "Share Text Example";
        request.Data.Properties.Description = "An example of how to share text.";
        request.Data.SetText("Hello World!");
    }
    
    function registerForShare() {
        var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
        dataTransferManager.addEventListener("datarequested", shareTextHandler);
    }
    
    function shareTextHandler(e) {
        var request = e.request;
        request.data.properties.title = "Share Text Example";
        request.data.properties.description = "A demonstration that shows how to share.";
        request.data.setText("Hello World!");
    }
    
  • Uri
    Uri
    Uri
    Uri
    Note

    Uri may be altered or unavailable for releases after Windows 8.1. Instead, use ApplicationLink or WebLink.

    A read-only property that returns the format ID string value corresponding to the Uniform Resource Identifier (URI) format.

    public static string Uri { get; }public static string Uri { get; }Public Static ReadOnly Property Uri As string

    Property Value

    • string
      string
      string
      string

      The format ID string value corresponding to the Uniform Resource Identifier (URI) format.

    Remarks

    Examples

    This example demonstrates the use of the Uri 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.

    public void ShareSourceLoad()
    {
        DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
        dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
    }
    
    void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
    {
        DataRequest request = e.Request;
        request.Data.Properties.Title = "Share Link Example";
        request.Data.Properties.Description = "An example of how to share a link.";
        var link = new Uri("http://www.fabrikam.com");
        request.Data.SetUri(link);
    }
    
    function registerForShare() {
        var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
        dataTransferManager.addEventListener("datarequested", shareLinkHandler);
    }
    
    function shareLinkHandler(e) {
            var request = e.request;
            request.data.properties.title = "Share Link Example";
            request.data.properties.description = "A demonstration that shows how to add a link (URI) to share.";
            request.data.setUri(new Windows.Foundation.Uri("http://www.fabrikam.com"));
    }
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.ApplicationModel.DataTransfer.dll