I'm trying to create a text file to send to the share charm. I'm using a pull operation because the process can take longer than the 200 milliseconds that is allocated to a normal sharing operation. I'm using the following code:
private async void OnDeferredShareRequestHandler(Windows.ApplicationModel.DataTransfer.DataProviderRequest e)
{
Windows.ApplicationModel.DataTransfer.DataProviderDeferral Deferral = e.GetDeferral();
try
{
Windows.Storage.IStorageFile TempFile = await Windows.Storage.ApplicationData.Current.TemporaryFolder.CreateFileAsync("TEMP", Windows.Storage.CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteTextAsync(TempFile, "test");
e.SetData(Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(TempFile));
}
catch (System.Exception exception)
{
ExceptionHandler(exception);
}
finally
{
Deferral.Complete();
}
}
But this isn't working. It throws the following error:
> An exception of type 'System.Exception' occurred in App.exe but was
> not handled in user code WinRT information: Unable to create
> StorageItems from the passed in object. Additional information: Type
> mismatch. Unable to create StorageItems from the passed in object. If
> there is a handler for this exception, the program may be safely
> continued.
What am I doing wrong? How can I fix this so that I can share the file properly?