locked
Setting up a pull operation for sharing a file

    Question

  • 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?

    Tuesday, June 10, 2014 1:56 PM

All replies

  • Which line of code is throwing the exception? Can you post a reproduction app for testing?

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, June 11, 2014 12:23 PM
    Moderator