zoukankan      html  css  js  c++  java
  • 资源文件

    在.NET项目中使用资源文件方式我知道的有二种:

    一、简单地将文件包含进项目
    这里写图片描述

    这里写图片描述

    调用方法:

    //注意这里的路径。资源文件Template.html放在"<根目录>Email"下,则资源文件的路径为 项目名称.Email.Template.html。是项目名称,而不是命名空间。
    Stream sm = Assembly.GetExecutingAssembly().GetManifestResourceStream("BaseLT.ShareTests.Email.Template.html");
    byte[] bs = new byte[sm.Length];
    sm.Read(bs, 0, (int)sm.Length);
    sm.Close();
    UTF8Encoding con = new UTF8Encoding();
    string str = con.GetString(bs);

    二、将文件添加进项目的资源
    这里写图片描述

    调用方法:

    string str = Properties.Resources.ResourceManager.GetObject("Template").ToString();

    以上两种方式,文件都跟项目编译在一起;其他方式的话,用File来直接进行访问当然也可以,但这样做,文件就跟项目没有啥直接联系,发布部署,要记得打包。

  • 相关阅读:
    数据库
    数据库
    数据库
    数据库
    数据库
    数据库
    windows
    LeetCode : Word Pattern
    LeetCode : Perfect Number
    LeetCode : Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/leftfist/p/6808672.html
Copyright © 2011-2022 走看看