locked
File Save Picker Contract Implementation

    Question

  • void FileSavePicker_SaveToAppStorage::OnTargetFileRequested(FileSavePickerUI^ sender, TargetFileRequestedEventArgs^ e)
    {
        auto request = e->Request;
        auto deferral = request->GetDeferral();

        create_task(ApplicationData::Current->LocalFolder->CreateFileAsync(sender->FileName, CreationCollisionOption::GenerateUniqueName)).then([request, deferral](StorageFile^ file)
        {
            // Assign the resulting file to the targetFile property indicates success
            request->TargetFile = file;

            // Complete the deferral to let the Picker know the request is finished.
            deferral->Complete();

    return file;

       }.then([=](StorageFile^ file)

    {

    if(file)

    {

    hr=uploadfunc(file);

    }

    else

    {

    hr=uploadFail(file);

    }

    });

    This was the code i tried, using the above code i was able to upload file but file is always 0bytes please help ............

    Sunday, September 23, 2012 3:00 PM

Answers

  • Hi,

    I think the upload function in your codes is incorrect.
    There are several way to upload a file in C++/CX, like IXHR2 and Background Transfer.
    I would suggest you to use these APIs in windows store app.
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh757628.aspx

    Quickstart: Uploading a file
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj152727.aspx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by sandbha Sunday, November 25, 2012 10:39 AM
    Monday, September 24, 2012 6:01 AM
  • deferral->complete need to be placed after uploading a file? or the above placed code is correct?
    • Edited by sandbha Tuesday, September 25, 2012 6:30 PM
    • Marked as answer by sandbha Sunday, November 25, 2012 10:39 AM
    Tuesday, September 25, 2012 6:29 PM
  • Hi Jesse

    I have implemented the FileSavePicker Contract in my app,so when user selects an attachment from mail app and want to save to my app ,then OnTargetFileRequested(FileSavePickerUI^ sender, TargetFileRequestedEventArgs^ e) method gets triggered....

    OnTargetFileRequested(FileSavePickerUI^ sender, TargetFileRequestedEventArgs^ e) 
    {
        auto request = e->Request;
        auto deferral = request->GetDeferral();

        create_task(ApplicationData::Current->LocalFolder->CreateFileAsync(sender->FileName, CreationCollisionOption::GenerateUniqueName)).then([request, deferral](StorageFile^ file)
        {
            // Assign the resulting file to the targetFile property indicates success
            request->TargetFile = file;

            // Complete the deferral to let the Picker know the request is finished.
            deferral->Complete();

    return file;

       }.then([=](StorageFile^ file)

    {

    //

    }

    now whatever file i was created that i need to upload to my metro app....but i am facing an issue with deferral->complete...whether deferral->complete() complete need to written after uploading the file to my app or above the deferral->complete statement is correct.??...

    but when i use deferral->complete after uploading the file always 0 bytes of file is getting uploaded...

    if i use deferral->complete in createFileAsync() as shown in above code then the file is not getting uploaded........please help me...

    • Marked as answer by sandbha Sunday, November 25, 2012 10:39 AM
    Tuesday, September 25, 2012 7:14 PM

All replies

  • Hi,

    I think the upload function in your codes is incorrect.
    There are several way to upload a file in C++/CX, like IXHR2 and Background Transfer.
    I would suggest you to use these APIs in windows store app.
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh757628.aspx

    Quickstart: Uploading a file
    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj152727.aspx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by sandbha Sunday, November 25, 2012 10:39 AM
    Monday, September 24, 2012 6:01 AM
  • deferral->complete need to be placed after uploading a file? or the above placed code is correct?
    • Edited by sandbha Tuesday, September 25, 2012 6:30 PM
    • Marked as answer by sandbha Sunday, November 25, 2012 10:39 AM
    Tuesday, September 25, 2012 6:29 PM
  • Hi Jesse

    I have implemented the FileSavePicker Contract in my app,so when user selects an attachment from mail app and want to save to my app ,then OnTargetFileRequested(FileSavePickerUI^ sender, TargetFileRequestedEventArgs^ e) method gets triggered....

    OnTargetFileRequested(FileSavePickerUI^ sender, TargetFileRequestedEventArgs^ e) 
    {
        auto request = e->Request;
        auto deferral = request->GetDeferral();

        create_task(ApplicationData::Current->LocalFolder->CreateFileAsync(sender->FileName, CreationCollisionOption::GenerateUniqueName)).then([request, deferral](StorageFile^ file)
        {
            // Assign the resulting file to the targetFile property indicates success
            request->TargetFile = file;

            // Complete the deferral to let the Picker know the request is finished.
            deferral->Complete();

    return file;

       }.then([=](StorageFile^ file)

    {

    //

    }

    now whatever file i was created that i need to upload to my metro app....but i am facing an issue with deferral->complete...whether deferral->complete() complete need to written after uploading the file to my app or above the deferral->complete statement is correct.??...

    but when i use deferral->complete after uploading the file always 0 bytes of file is getting uploaded...

    if i use deferral->complete in createFileAsync() as shown in above code then the file is not getting uploaded........please help me...

    • Marked as answer by sandbha Sunday, November 25, 2012 10:39 AM
    Tuesday, September 25, 2012 7:14 PM