locked
FileAccess Error when running in vs2011 debug/run or debug/debug, deploy, then run from metro works RRS feed

  • Question

  • How can I debug reading and writing to a file and debug at the same time?  I've noticed all the examples (including my app) fail when they include access to the local file system.  I get the JavaScript error "File Access Denied".

     

    Below is the simple javascript from the fileaccess example provided.

     

    function allLegislatorsCreateFile() {
        //Create a empty file sample.txt in user's Document folder, replacing/overwrite the existing file to ensure there is only file be created.
        Windows.Storage.KnownFolders.documentsLibrary.createFileAsync("legislatorsAll.txt",
                Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
            id("statusFieldId").innerHTML = '<p>The file <b>legislatorsAll.txt</b> was created.</p>';
            sampleFile = file;
        });
    }
    



    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    Monday, December 26, 2011 8:07 PM

Answers

  • Hi Peter,

    The Documents folder is a special access case.  In order to access files in that folder you need to add that extension to the application manifest.  You do that in the declarations tab of your manifest, add a 'File Type Association' for the .txt files and it should work!

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, December 27, 2011 3:22 PM
    Moderator
  • Open your app manifest, and specify the File Type Association as below:

    And " is there a better place I should be creating application specific files than mydocs?" Please read the Application Data document, I think it can help you.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Jie Bao Monday, January 2, 2012 9:20 AM
    Monday, January 2, 2012 9:20 AM

All replies

  • Hi Peter,

    The Documents folder is a special access case.  In order to access files in that folder you need to add that extension to the application manifest.  You do that in the declarations tab of your manifest, add a 'File Type Association' for the .txt files and it should work!

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, December 27, 2011 3:22 PM
    Moderator
  • Could you please show me an example of what should be in the manifest?  the wizard is pretty worthless at explaining what values should be, and when I guess, that has even less value.  If you could cut and paste what should go in the manifest, as well as the 3 lines of javascript to create a file in mydocs, I'd appreciate that.

    Also, is there a better place I should be creating application specific files than mydocs? I don't want the user to see these files when they go into my docs. they are things like me caching what is coming back from JSON calls.

    thanks.


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    Saturday, December 31, 2011 3:12 AM
  • Open your app manifest, and specify the File Type Association as below:

    And " is there a better place I should be creating application specific files than mydocs?" Please read the Application Data document, I think it can help you.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    • Marked as answer by Jie Bao Monday, January 2, 2012 9:20 AM
    Monday, January 2, 2012 9:20 AM