Requirement: Share a text and image using DataTransferManager
into Facebook in Windows 10.
Problem: Unable to share image.
Below shown is the code I used,
private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
DataRequestDeferral deferral = args.Request.GetDeferral();
args.Request.Data.Properties.Title = "Sharing sample";
args.Request.Data.SetText("Testing share in universal app");
var imageUri = "http://cdn.vrworld.com/wp-content/uploads/2015/01/microsoft-announces-windows-10_ahab.1920.jpg";
//var storageFile = await StorageFile.CreateStreamedFileFromUriAsync("ShareFile", new Uri(imageUri), null);
//List<IStorageItem> storageItems = new List<IStorageItem>();
//storageItems.Add(storageFile);
//args.Request.Data.SetStorageItems(storageItems);
args.Request.Data.SetBitmap(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromUri(new Uri(imageUri)));
deferral.Complete();
}
When I use SetBitmap
method, only the title and text are being shared. The image is neither displayed in the share panel nor shared to the target app.
When I use SetStorageItems
(see commented code), none of the items are shared. The default "What's on your mind" text appears on the share panel.
Any feedback is appreciated, thank you!
Sharing of URI streamed files is unfortunately not supported. Here's how I would go about doing this:
StorageFile
instance
containing the file. DataRequested
handler, use SetStorageItems
to share the StorageFile
instance.