2012-04-27 51 views
-2

我有我的dll文本文件。每當我嘗試從我的.exe程序訪問它時,它都會失敗,因爲它試圖從我的.exe程序中找到該文件。無論如何,我可以去做這件事。從我的dll訪問文件

+7

你能解釋一下嗎?你能分享代碼嗎? – 2012-04-27 14:44:53

+1

您需要加載DLL的程序集而不是執行程序集。 – 2012-04-27 14:47:20

回答

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