-2

我的 dll 中有一个文本文件。每当我尝试从我的 .exe 程序访问它时,它都会失败,因为它试图从我的 .exe 程序中查找该文件。请问有没有我可以解决这个问题。

4

1 回答 1

3

您需要加载程序集并使用资源管理器可以检索文本文件,如下所示

// Gets a reference to the same assembly that 
// contains the type that is creating the ResourceManager.
System.Reflection.Assembly myAssembly = typeof(Program).Assembly;

// Gets a reference to a different assembly.
System.Reflection.Assembly myOtherAssembly;
myOtherAssembly = System.Reflection.Assembly.Load("ResourceAssembly");

// Creates the ResourceManager.
System.Resources.ResourceManager myManager = new 
   System.Resources.ResourceManager("ResourceNamespace.myResources", 
   myAssembly);

// Retrieves String and Image resources.
UnmanagedMemoryStream x = myManager.GetStream("StringResource");

欲了解更多信息,请访问

http://msdn.microsoft.com/en-us/library/aa984408%28VS.71%29.aspx

于 2012-04-27T14:52:42.577 回答