none
Read a HTML file using Application.GetResourceStream is always null

    问题

  • Hello

    i'm developing a WP7 app and i need to invoke a javascript function using webBrowser.I try to do this:

    How to: Display Static Web Content Using the WebBrowser Control for Windows Phone

    when i use a html file in in

    SaveFilesToIsoStore()

    the result of this

    StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));

    is always null :(

    I set the build Action of myfile.html with Content and Always Copy.

    When i try this using a txt file the sr is not null. But i want a html file, beacause i need invoke a javascript funtion inside them.

    Why cannot read the html file?

    2012年3月6日 23:10

全部回复

  • I'm no expert on ISO storage but if you put the code into debug mode you may be able to figure this out...  Put a break point on the BinaryWriter and note the filename.  But also note just above that there is a directory that is created.  Note that as well. 

      //Get the IsoStore.
            IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();

            //Re-create the directory structure.
            for (int i = 0; i < dirsPath.Length - 1; i++)
            {
                strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
                isoStore.CreateDirectory(strBaseDir);
            }

            //Remove the existing file.
            if (isoStore.FileExists(fileName))
            {
                isoStore.DeleteFile(fileName);
            }

            //Write the file.
            using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(fileName)))
            {
                bw.Write(data);
                bw.Close();
            }

    Then look at this line in your code and compare note.  The first question I have is GetResourceStream wants a URI..  That to me would make me wonder how ISO storage ties into URIs?  I don't know the answer but that would be my first point of investigation.  Notice also that the URIKING.RELATIVE means realtive to where the current directory of the application is located.  You can have the program tell you which directory that is by posting a message to yourself using http://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory.aspx  (GetCurrentDirectory)...

    StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));

    Those two tips should help you to discover the answer.    I don't know if ISO storage supports the funky Pack:// syntax  or not.


    JP Cowboy Coders Unite!

    2012年3月6日 23:27