从我的dll访问文件

时间:2012-04-27 14:44:20

标签: c# .net dll

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

1 个答案:

答案 0 :(得分:4)

您需要加载程序集并使用resourcemanager,您可以检索文本文件,如下所示

// 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