locked
File Rename/Copy gives error - Access Denied RRS feed

  • Question

  • Hi,

    I have a windows metro app, whre in I try to copy or rename the file. This file is present is the public documents folder, so there is no question of access rights. But I still get access denied error, wondering why it occurs?

     IReadOnlyList<StorageFile> feedbackFiles = await HistoryFolder.GetFilesAsync();
                    
                    List<Type> knownTypeList = new List<Type> { typeof(MessageHeader), typeof(MessageBase) };
    
                    foreach (StorageFile file in feedbackFiles)
                    {
                        if(!file.Name.EndsWith("_bkp"))
                        {
                          await file.CopyAsync(HistoryFolder, "test", NameCollisionOption.ReplaceExisting);
                           
                            
                        }
                    }

    Wednesday, October 9, 2013 6:30 AM

Answers

  • Hi Shanthi,

    I tried my suggestion code (RenameAsync) and works fine. I think the reason might be you did not declarer the file type correctly in Manifest.

    Unlike other libraries, your app must use the File Type Association declaration in the app manifest file to explicitly declare what file types (extensions) will be accessed or created in the Documents library.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, October 9, 2013 7:51 AM
    Moderator

All replies

  • Hi Shanthi,

    While using file.CopyAsync, it works like write the file to a locked document, of course an access denied error occurs.

    To avoid this error, you could have following methods:

    1, Read file and then Write file by using Quickstart: Reading and writing a file, then you could rename the file.

    2, You can use RenameAsync | renameAsync methods to rename the file.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, October 9, 2013 7:01 AM
    Moderator
  • RenameAsync method also gives 'Access denied' error.
    Wednesday, October 9, 2013 7:14 AM
  • Hi Shanthi,

    I tried my suggestion code (RenameAsync) and works fine. I think the reason might be you did not declarer the file type correctly in Manifest.

    Unlike other libraries, your app must use the File Type Association declaration in the app manifest file to explicitly declare what file types (extensions) will be accessed or created in the Documents library.

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Wednesday, October 9, 2013 7:51 AM
    Moderator