locked
WinJS.Application.local.writeText promise doesn't give the number of characters written

    Question

  • Hello all,

    I've seen in the doc (http://msdn.microsoft.com/fr-fr/library/windows/apps/hh700832.aspx) that WinJS.Application.local.writeText returns a Promise containing the number of characters written.

    When I debug my code, the Promise have only one arg which is set to "undefined".

    Am I missing something?

    EDIT: in a Universal App, it occurs on both Windows and Windows Phone platforms.

    I've dug in base.js and the comments regarding the function also mention that the char count is passed along the returned Promise.

    Thursday, August 28, 2014 10:05 AM

Answers

  • It's a documentation bug, which originates in the header comments for that function from which the documentation is built. If you look in the WinJS sources (base.js) at the implementation of writeText, it delegates to Windows.Storage.FileIO.writeTextAsync to do its work. That particular API does not provide any result with the number of bytes written, hence your seeing the "undefined." It's possibly a leftover from behavior of WinRT APIs in preview builds of Windows 8. In any case, the documentation is incorrect.

    You can file this bug at https://github.com/winjs/winjs/issues.

    Sunday, August 31, 2014 4:56 AM

All replies

  • Hi Pierre,

    I would suggest you to talke a look at the documentation: Quickstart: using promises in JavaScript

    I would use following code to work with a Promise method.

    WinJS.Application.local.writeText("foo.html", "hello world").then(function (c) {
         // write your logical here.
        });
    
    

    --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.

    Friday, August 29, 2014 10:52 AM
    Moderator
  • Hi James,

    Thanks for your answer, I know how to use a promise, my point is that if you test your own code, the "c" variable is set to "undefined" instead of being set to the number of characters written by the function (11 in your sample) like the documentation states.

    I think it's a bug.

    Pierre 

    Friday, August 29, 2014 8:45 PM
  • It's a documentation bug, which originates in the header comments for that function from which the documentation is built. If you look in the WinJS sources (base.js) at the implementation of writeText, it delegates to Windows.Storage.FileIO.writeTextAsync to do its work. That particular API does not provide any result with the number of bytes written, hence your seeing the "undefined." It's possibly a leftover from behavior of WinRT APIs in preview builds of Windows 8. In any case, the documentation is incorrect.

    You can file this bug at https://github.com/winjs/winjs/issues.

    Sunday, August 31, 2014 4:56 AM
  • Ok, thanks Kraig!

    EDIT: the link to file the bug leads to a 404

    EDIT2: it's because of the ending "."

    Sunday, August 31, 2014 6:46 AM