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控件访问;
  • 相关阅读:
    Red hat 5挂载U盘
    Win7+VMware Workstation环境下的CentOS-Linux网络连接设置
    rand()随机数的产生
    phpmyadmin数据库导入出错
    dede忽略错误
    wamp
    网页地图map
    Redefining already defined constructor
    SCREAM:Error suppression ignored for
    Python+selenium之疑难点解决之去除readonly的限制
  • 原文地址:https://www.cnblogs.com/ngnetboy/p/2436400.html
Copyright © 2011-2022 走看看