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 | C#, embedded, 類別庫, 資源, library, resources, 內嵌 | 1 Comment
1 Comment »
-
The Host
關於麥克斯
文章分類
- 科技與人生 (21)
- Linux (8)
- Eletronic (1)
- 台灣情 (3)
- 學習程式之道 (132)
- Computer Science Knowledge (6)
- Misc (3)
- Programming (77)
- Project (4)
- IrrTetris (1)
- ZidduDownloader (3)
- Project (4)
- Server (14)
- Tools (4)
- Web (27)
- Image (1)
- 科技與人生 (21)
-
Top Posts
Subscribe My Blog
-
Recent Comments
Tags
.Net AJAX ASP ASP.NET branch C# chart CSS Driver feisty fawn FF Google Map hack hotkey hover html Icefaces IE irrlicht java JavaScript JBoss JIRA Junit Linux ListView mysql Netbeans Open Xml Portlet ReportViewer scim spreadsheetML SQL server SQL server 2008 Express svn template Tomcat tomcat 6 transparency ubuntu User Control UTF-8 website z-indexCategory Cloud
其他功能
封存文章
-
Blog Stats
- 36,242 人路過
-
Spam Blocked
Scott Gu
Rick Strahl
MS MVP DBA
DotBlogs
暗黑執行緒
TheWillWillWeb
猴子靈藥
Weithenn
MS MVP 馬小靈
Eddie
{|ihower.idv.tw| blog }
網絡暴民 Jacky’s Blog
Peace Palace – 技術、評論、生活
百分百無聊人生- An error has occurred; the feed is probably down. Try again later.
[...] 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 |