locked
Share - request.Data.SetStorageItems invalid parameter invalid RRS feed

  • Question

  • I have just added some share code to my project from the example at http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh871371.aspx translated to VB.  I do have a logo.png in Assets.

    Everything works fine till I get to the line "request.Data.SetStorageItems(storageItems)" which returns "The Parameter is incorrect".  The preceding add statement was successful and I have a count of 1 for the list.

     Private Async Sub ShareStorageItemsHandler(sender As DataTransferManager, e As DataRequestedEventArgs)
            Dim request As DataRequest = e.Request
            request.Data.Properties.Title = "Share StorageItems Example"
            request.Data.Properties.Description = "Demonstrates how to share files."
    
            ' Because we are making async calls in the DataRequested event handler,
            ' we need to get the deferral first.
            Dim deferral As DataRequestDeferral = request.GetDeferral()
    
            ' Make sure we always call Complete on the deferral.
            Try
                Dim logoFile As Windows.Storage.StorageFile = _
                    Await Package.Current.InstalledLocation.GetFileAsync("Assets\\Logo.png")
                Dim storageItems As List(Of Windows.Storage.IStorageItem) = New List(Of Windows.Storage.IStorageItem)
                storageItems.Add(logoFile)
                request.Data.SetStorageItems(storageItems)
            Catch ex As Exception
                Dim sStr As String = ex.Message
            Finally
                deferral.Complete()
            End Try
         End Sub
    

    Saturday, April 27, 2013 7:15 PM

Answers

  • I think you should copy your asset Logo.png to Windows.Storage.ApplicationData.Current.LocalFolder.
    InstalledLocation folder is a special folder and I don't know if you can share stuff from there.

    It is also read-only and you need special permissions to access it manually through file explorer.
    The fastest way to try this feature is by using FilePicker and choose a picture or copy something to LocalFolder.


    • Proposed as answer by Jernej Kavka Sunday, April 28, 2013 5:51 PM
    • Edited by Jernej Kavka Sunday, April 28, 2013 7:31 PM Incorrect LocalFolder naming.
    • Marked as answer by Aaron Xue Wednesday, May 8, 2013 10:08 AM
    Sunday, April 28, 2013 5:51 PM

All replies

  • I think you should copy your asset Logo.png to Windows.Storage.ApplicationData.Current.LocalFolder.
    InstalledLocation folder is a special folder and I don't know if you can share stuff from there.

    It is also read-only and you need special permissions to access it manually through file explorer.
    The fastest way to try this feature is by using FilePicker and choose a picture or copy something to LocalFolder.


    • Proposed as answer by Jernej Kavka Sunday, April 28, 2013 5:51 PM
    • Edited by Jernej Kavka Sunday, April 28, 2013 7:31 PM Incorrect LocalFolder naming.
    • Marked as answer by Aaron Xue Wednesday, May 8, 2013 10:08 AM
    Sunday, April 28, 2013 5:51 PM
  • I will try that, but this is straight from the example, so that was what I was trying. I actually have a .txt ascii file that I want to share (send in an email).  Its supposed to make a copy of it.

    It goes all the way thru to that one line of code, the last one, and fails.  Seems to be looking for not a list. A list is needed and used in the example.  That allows you to share multiple files.  The Intellisense is asking for system.collections.generic.ienumerable(of windows.storage.istorage) which does not match the type for storageIitems  var (not a list).  I've gone back and tried to change all the others definitions, but so far, no luck.

    I probably just need to find another example. Its hard to find vb example code for store apps, so I do some translating from c#.

    Different issue, but ill mention it in case someone else has similar problems.  If I navigate away to a different page, then back, I get an error.  It seems to be re-adding the event handler.  I'm currently looking for the answer for that.  I put in a try catch, and am just bypassing the error right now.  Not a good solution.

    Monday, April 29, 2013 12:23 AM
  • Try to add this line before adding files:

    args.Request.Data.Properties.FileTypes.Add("*.txt");

    I looked a bit deeper in my projects and I noticed that I required this line in some cases but not always.


    EDIT: You should add event for sharing in OnNavigatedTo/LoadState event and remove it in OnNavigatedFrom/SaveState.
    Putting it into Unloaded event may cause some issues.
    • Edited by Jernej Kavka Monday, April 29, 2013 7:38 AM Added an additional answer
    Monday, April 29, 2013 5:57 AM
  • I think that was probably going to be a problem, just had not gotten that far yet  I did some searching and on one link, that had to be added as you suggested, but for a different problem. I added it for a .png since that is the file type that were currently trying to share.

         request.Data.Properties.FileTypes.Add("*.png")

    It made no difference.  So now, I am still trying to figure out how to populate some variable that request.data.setStorageItems will accept in VB.  Since it seems to work just fine in C#, I'm beginning to wonder if the VB implementation has an error.  I hate to say something like that.  Its always wrong.

    One other note.  I put a break on my error catch for the try.  If I stop the run  and do not execute the finally  deferral.complete(), it will never again enter the sub. That process is somewhere running and I have not as yet figured out what process to kill of in task manager to clear it.  I am having to re-boot the computer to get another run.  Its ok if I step thru and do that line of code. So if anyone is working on this, don't stop the run.  Let it continue on to this line executes, then you can stop the debug.

    BTW:  thanks for looking at the problem.

    Monday, April 29, 2013 2:16 PM