Reading Files in Windows Phone 8: Value does not fall within the expected range

前端 未结 1 1893
一个人的身影
一个人的身影 2021-01-23 14:32

I\'m really problems when open files stored in my project. I need open some files (pdf, html,...) and ever has the same problem: Value does not fall within the expected

相关标签:
1条回答
  • 2021-01-23 15:00

    I noticed that I get that error if I use the shash / in the path to the file. Instead, if I use backslash \ I can get the files.

    Try following way:

    StorageFile sFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\Data\htm\" + fileName + ".htm");
    
    var fileStream = await sFile.OpenStreamForReadAsync();
    

    Note that you have to place an @ before the path string to avoid the intepretation of \ as scape character.

    You could also get the file stream this way:

    var fileStream = File.OpenRead("Assets/Data/htm/" + fileName + ".htm");
    
    0 讨论(0)
提交回复
热议问题