麥克斯做個不宅的工程師

Maxi’s idiotic programming.

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.resources.images.MaxiIcon.png

檔案字串語法為:
方案名稱.資料夾.[子資料夾].檔案名.副檔名
例如, 如果我的方案叫MaxiProject,我的檔案叫MaxiIcon.png並位於方案根目錄/resources/images. 那麼我的檔案字串應該是:
MaxiProject.resources.images.MaxiIcon.png

March 25, 2009 , Wednesday - Posted by maxi326 | Programming | , , , , , , | 1 Comment

1 Comment »

  1. [...] I use them to load an embedded font. About how to embedded a file as resource is in another post HERE. [...]

    Pingback by Unsafe and Fixed, unmanaged code in C# « 麥克斯做個不宅的工程師 | April 10, 2009 , Friday |


Leave a comment

You must be logged in to post a comment.