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控件访问;
  • 相关阅读:
    Java经典面试题及详解
    linux nc命令使用详解
    终端下更改文件显示颜色
    第二章 IoC Setter注入
    网络抓包wireshark
    一些软件软件开发原则
    开发原则之约定大于配置
    2016第31周六
    2016第31周五
    2016年第31周四
  • 原文地址:https://www.cnblogs.com/ngnetboy/p/2436400.html
Copyright © 2011-2022 走看看