C # embed a resource file

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.