none
Wanting to read a file from my Metro Project / How?

    שאלה

  • I have a Metro project that I've put a file in the root directory + "data" called:

    C:\VSProjects\USGov\data\myfile.json

    I want to read this file and can't figure out how to.  I can read files in a temp directory using code like I have below, but I want to include this file in my distribution.  

    Once I figure this out, I'm going to be hit with a second problem which is readString fails with an error on my JSON. How can I read this large json file (.5MB) without getting errors.

     

    dataFile.openAsync(Windows.Storage.FileAccessMode.read).then(function (stream) {
                    var size = stream.size;
                    if (size == 0) {
                        // Data not found
                    }
                    else {
                        var inputStream = stream.getInputStreamAt(0);
                        var reader = new Windows.Storage.Streams.DataReader(inputStream);
    
                        reader.loadAsync(size).then(function () {
                            var contents = reader.readString(size);
    ...
    


     


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    יום שני 02 ינואר 2012 21:36

תשובות

  • Hi Jeff,

    "StorageFile                 sf = await Package.Current.InstalledLocation.GetFileAsync" means nothing to me.  Is Package a namespace? it does not show up in the WinRT api list for JavaScript (or c# for that matter which is where it is posted).

    Can you please give me an example in JavaScript similar to my code above that will allow me to open and read the file.  I combined it in one questions because open and read are usually together in the same example.  If you still want me to create another thread for this question I will but to me it seems unnecesary.



    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider
    • סומן כתשובה על-ידי Peter KellnerMVP יום שלישי 03 ינואר 2012 19:23
    יום שלישי 03 ינואר 2012 16:39
  • Sorry Peter I go back and forth between the two I forgot where you were posting and put in the C# thread.

    The documentation has an example of how to use these objects for each language (normally).

    Here is the documentation for that API:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.package.installedlocation.aspx

    You should be able to use that the same way you are using storage folders in javascript today.

    If you need some examples for using storage folders, check out the documentation or samples and they should help you along (any of the picker examples should be adequate!

    -Jeff


    Jeff Sanders (MSFT)
    יום שלישי 03 ינואר 2012 16:49
    מנחה דיון

כל התגובות