zoukankan      html  css  js  c++  java
  • 从xap文件中读取文件

    读取图片文件:

    SteamResourceInfo sri=Application.GetResourceStream(new Uri("filename;component/assets/"+dm.spic,UriKind.Relative));
    BitmapImage bi
    =new BitmapImage();
    bi.SetSource(sri.Stream);
    Image img
    =new Image();
    img.Source
    =bi;

    读取XML文件并用Linq来初始化数据:

    public void InitDataMode() {
    StreamResouceInfo sri
    =Application.GetResourceStream(new Uri("filename;component/Data/DataModel.xml",UriKind.Relative));
    XmlReader reader
    =XmlReader.Create(sri.Stream);
    XDocument document
    =XDocument.Load(reader);
    listData
    =(from c in document.Descendants("model")
        select 
    new DataModel
        {
          t1
    =c.Element("t1").Value,
          t2
    =c.Element("t2").Value,
          t3
    =c.Element("t3").Value,
          url
    =c.Element("url").Value,
          spic
    =c.Element("spic").Value,
          bpic
    =c.Element("bpic").Value
        }).ToList
    <DataModel>();
    sri.Stream.Close();
    sri.Stream.Dispose();
    }

    注解:

    StreamResourceInfo sri = Application.GetResourceStream(new Uri("{0};component/{1}", UriKind.Relative));

    0为xap程序集的名字,

    1为要读取的文件在在xap中的路径。

  • 相关阅读:
    双指针
    二分查找
    二叉树
    递归思想
    排序算法
    Java常用集合使用方法总结
    攻防世界-PHP文件包含
    正则表达式随笔
    ts 函数
    ts 联合类型
  • 原文地址:https://www.cnblogs.com/lovecode/p/1403393.html
Copyright © 2011-2022 走看看