写resource: using System; using System.Resources; public class WriteResources { public static void Main(string[] args) {
// Creates a resource writer. IResourceWriter writer = new ResourceWriter("myResources.resources");
// Adds resources to the resource writer. writer.AddResource("String 1", "First String"); writer.AddResource("String 2", "Second String"); writer.AddResource("String 3", "Third String"); // Writes the resources to the file or stream, and closes it. writer.Close(); } }读resource: using System; using System.Resources; using System.Collections;
public class ReadResources { public static void Main(string[] args) { // Opens a resource reader and gets an enumerator from it. IResourceReader reader = new ResourceReader("myResources.resources"); IDictionaryEnumerator en = reader.GetEnumerator();
// Goes through the enumerator, printing out the key and value pairs. while (en.MoveNext()) { Console.WriteLine(); Console.WriteLine("Name: {0}", en.Key); Console.WriteLine("Value: {0}", en.Value); } reader.Close(); } }
http://www.daima.com.cn/Info/89/Info31054/
http://bin270.blogchina.com/4943605.html
using System;
using System.Resources;
public class WriteResources {
public static void Main(string[] args) {
// Creates a resource writer.
IResourceWriter writer = new ResourceWriter("myResources.resources");
// Adds resources to the resource writer.
writer.AddResource("String 1", "First String"); writer.AddResource("String 2", "Second String"); writer.AddResource("String 3", "Third String"); // Writes the resources to the file or stream, and closes it.
writer.Close();
}
}读resource:
using System;
using System.Resources;
using System.Collections;
public class ReadResources { public static void Main(string[] args) { // Opens a resource reader and gets an enumerator from it.
IResourceReader reader = new ResourceReader("myResources.resources");
IDictionaryEnumerator en = reader.GetEnumerator();
// Goes through the enumerator, printing out the key and value pairs.
while (en.MoveNext()) {
Console.WriteLine();
Console.WriteLine("Name: {0}", en.Key);
Console.WriteLine("Value: {0}", en.Value);
}
reader.Close();
}
}
http://bin270.blogchina.com/4943605.html
正是我现在所采用的,但是要编译,使.txt--->.resource文件,有些麻烦,所以想寻求直接插入的方法,当打开"解决方案资源管理器",右键,依次选择"添加\添加组件",在模板中选择"程序集资源文件",我要从这个资源文件中直接读取数据,不用编译了,八仙过海,解决问题者高分奉上!
ResourceWriter rw = new ResourceWriter("mytest.resources");
rw.AddResource("test_2","今天六一儿童节!");
rw.Generate();
rw.Close();
ResourceManager rm = ResourceManager.CreateFileBasedResourceManager(Server.MapPath("../mytest"),".",null);
this.Label.Text=rm.GetString("test_2");
http://blog.csdn.net/FollowIT/archive/2006/06/02/769816.aspx