zoukankan      html  css  js  c++  java
  • 【windows phone】读取资源文件

    • 读取txt文件

        如果在项目中附加一个文件的时候,需要设置文件的Build Action属性,如果设置为content ,你会在“bin”文件夹中的xap包中发现此文件;(xap:把xap文件后加上.zip会变成一个压缩包,解压后会发现里面的内容)如果设置为resource,文件会添加到项目文件的dll文件中。

                //读取属性Build Action为content的txt文件

    //用stream获取文件的二进制流

    Stream st = Application.GetResourceStream(new Uri("files/firle1.txt", UriKind.Relative)).Stream;

    string str = new StreamReader(st).ReadToEnd();

    MessageBox.Show(str);



    //读取属性Build Action为Resource的txt文件

    Stream st1 = Application.GetResourceStream(new Uri("/demo(项目名称);component/files/firle2.txt", UriKind.Relative)).Stream;

    string str1 = new StreamReader(st1).ReadToEnd();

    MessageBox.Show(str); 
    • 图片文件可以通过URI访问

    添加引用

    using System.Windows.Media.Imaging;

                Uri uri = new Uri("/image/text.jpg", UriKind.Relative);

    BitmapImage bmp = new BitmapImage(uri);

    image1.Source = bmp;

    • XML文件可以借助XElement.Load()方法访问
    • 多媒体文件可以通过MediaPlayerElement控件访问;
  • 相关阅读:
    Exercise02_09
    Exercise02_05
    Exercise02_01
    Exercise02_03
    Exercise02_07
    web.xml配置详解
    面对不成功的人生
    请不以结婚为目的的恋爱吧
    年轻人能为世界做点什么
    不作就不会活
  • 原文地址:https://www.cnblogs.com/ngnetboy/p/2436400.html
Copyright © 2011-2022 走看看