locked
Deleting a file doesnt seem to work

    Question

  •  I am trying to delete a a file using Windows::Storage::StorageFile::DeleteAsync() method. But it doesnt seem to work. The errorcode returns 0.  The file never gets deleted. Am I doing something wrong?

    auto statusOperation = tempFile->DeleteAsync(StorageDeleteOption::PermanentDelete);
                   statusOperation->Completed = ref new AsyncActionCompletedHandler([](IAsyncAction ^asyncInfo)
                    {
                        auto errorcode = asyncInfo->ErrorCode;
                    });
                    statusOperation->Start();

    Friday, March 2, 2012 7:38 PM

All replies

  • Hi,

    Please note that Start method is not defined in IAsyncAction interface. So your code cannot pass compilation.

    Please try the following code snippet.

    task<void>(tempFile->DeleteAsync(StorageDeleteOption::PermanentDelete).then([this]() {......});

    Please refer to File access sample for more details.

    In the meantime, please check if this file is being accessed by other apps.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 5, 2012 6:27 AM
    Moderator
  • Let us know if you have any issues in Consumer Preview using DeleteAsync as demonstrated in the File Access sample Robin shared.

    Thanks,

    -David

    Monday, March 5, 2012 4:24 PM
    Moderator
  • I am facing issues regarding with the DeleteAsync Api. I am using BackgroundDownload api's to access data from a web service and storing it to a temporary file which i want to delete. The delete operation is executed , but i still see the app in the local data store of the app when the app is still in execution. At this point if I try to manually open the file in windows explorer, it say access denied. The file seems to actually get deleted from the local app data store only when the application is quit ! 

    the problem is on a second run of creating the temporary file, instead of creating temp(2), the application seems to think there is a file with name temp. The app at this point throws an exception it says WWAhost.exe has thrown an exception.

    I do need to delete the temporary files that i create after the json data is downloaded and read.

    Wednesday, March 14, 2012 6:16 AM