Development Environment: vs2005 C #
First, copy the resources to be embedded to the project directory.
Set file generation to embedded Resources
Get embedded assetSource codeAs follows:
Private void form1_load (Object sender, eventargs e) {stream Sm = assembly. getexecutingassembly (). getmanifestresourcestream ("windowsapplication3.embedded into cmd.txt"); byte [] BS = new byte [Sm. length]; SM. read (BS, 0, (INT) Sm. length); SM. close (); utf8encoding con = new utf8encoding (); string STR = con. getstring (BS); MessageBox. show (STR );}
Note:Windowsapplication3.Embedded into cmd.txtWindowsapplication3 is the project name
Instance download: http://files.cnblogs.com/zjfree/Embed.rar
Use the system embedded Resource function
Assume that the project name is:Windowsapplication3
Open the menu [project]-[properties] and select [Resource] [Add Resource] [add existing file] and select resource file to set Resource Name
InProgramHow to Use
Soundplayer play = new soundplayer (windowsapplication3.properties. Resources. Warning); play. Play ();