Embedding resources in library 內嵌資源到類別庫

1. Add the file into your project.
2. click it in the project explorer, go to the properties window, apply ’embedded resources’ to build action.
3. use Assembly to get the file stream.

1. 新增一個檔案到你的方案
2. 在方案總管,選擇剛才的檔案,在屬性窗口找建置動作,設定為內嵌資源.
3. 用Assembly類別去取得檔案資料流.

Assembly l_library = Assembly.GetExecutingAssembly();
Stream l_fileStream = l_library.GetManifestResourceStream("file string");

Explain, the file string is in this format :
ProjectName.folder.[sub folder].filename.extension
for example, if my project is MaxiProject, my file MaxiIcon.png is under project root/resources/images. Then my file string will be as follow :

例如, 如果我的方案叫MaxiProject,我的檔案叫MaxiIcon.png並位於方案根目錄/resources/images. 那麼我的檔案字串應該是:


One thought on “Embedding resources in library 內嵌資源到類別庫

  1. Pingback: Unsafe and Fixed, unmanaged code in C# « 麥克斯做個不宅的工程師

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s