locked
SaveToWICFile save file path problem ? (Win8/C++/Cx/DirectX)

    Question

  • Before I saved the file in Windows::Storage::ApplicationData::Current->LocalFolder. The result was good.

    Next, I want to save the file in user chose path , but it always fail.

    Error:E_ACCESSDENIED General access denied error.

    So, The point is the file save path. How to solve this problem ?  

    Below my code. 

    FileSavePicker^ SavePicker = ref new FileSavePicker();
    SavePicker->SuggestedStartLocation = PickerLocationId::DocumentsLibrary;
    
    auto plainTextExtensions = ref new Platform::Collections::Vector<String^>();
    plainTextExtensions->Append(".jpg");
    SavePicker->FileTypeChoices->Insert("Model",plainTextExtensions);
    SavePicker->SuggestedFileName = "ModelFileName";
    create_task(SavePicker->PickSaveFileAsync()).then([this]( StorageFile^ file )
    {
            if (file != nullptr)
            {
             hr = SaveToWICFile( *SrcImg,DirectX::WIC_FLAGS_NONE , GUID_ContainerFormatJpeg , file->Path->Data() );
            }
    });


    • Edited by KC-Steven Friday, February 7, 2014 6:31 AM
    Friday, February 7, 2014 6:30 AM

Answers

  • Correct. SaveToWICFile can only save to locations the app has direct access: it's app data directories.

    After saving there you can copy it elsewhere with the StorageFile API.

    --Rob

    • Marked as answer by KC-Steven Monday, February 10, 2014 2:51 AM
    Monday, February 10, 2014 1:24 AM
    Moderator

All replies

  • The error is correct: the app doesn't have direct access to the picked file. It can only access it via the file broker (i.e with the StorageFile class). The app has direct write access to its app data directories.

    I discussed this in more detail in my blog entry at http://blogs.msdn.com/b/wsdevsol/archive/2012/12/05/stray-from-the-path-stick-to-the-storagefile.aspx


    Friday, February 7, 2014 2:08 PM
    Moderator
  • First, thank you very much.
    I known your blog.

    You say " It can only access it via the file broker (i.e with the StorageFile class). "

    So, I always think my code about "SavePicker->PickSaveFileAsync()).then([this]( StorageFile^ file )".

    The output is StorageFile^ file. I think it ok , but It fail.

    I miss some points.  I want to known it.

    Saturday, February 8, 2014 12:27 AM
  • SaveToWICFile requires direct write access to the target location. Note that you pass a path to it and not a StorageFile.

    This is called out in the DirectXTex docs at http://directxtex.codeplex.com/wikipage?title=WIC%20I%2fO%20Functions (scroll to the bottom of the page).

    --Rob

    Saturday, February 8, 2014 12:38 AM
    Moderator
  • Sorry, My C++/Cx is poor.

    "SaveToWICFile requires direct write access to the target location."

    So, If I save image by SaveToWICFile , I can't choose path by User?

    Could you teach me how to solve this problem.

    This problem let me not sleep . Help !



    • Edited by KC-Steven Monday, February 10, 2014 12:55 AM
    Monday, February 10, 2014 12:50 AM
  • Correct. SaveToWICFile can only save to locations the app has direct access: it's app data directories.

    After saving there you can copy it elsewhere with the StorageFile API.

    --Rob

    • Marked as answer by KC-Steven Monday, February 10, 2014 2:51 AM
    Monday, February 10, 2014 1:24 AM
    Moderator
  • Oh , I got it. ~><

    Thanks very much.

    I was moved to tears.

    Monday, February 10, 2014 2:52 AM
  • Note that if you are just going to create the file and then use StorageFile to copy it elsewhere, you could write it to the temporary folder rather than pollute up your app data folder.

    auto folder = Windows::Storage::ApplicationData::Current->TemporaryFolder;
    // use folder->Path->Data() as the path base

     
    Tuesday, February 11, 2014 10:33 PM