Embedded resources Lecture 3: Embedded WPF resource files in Multi-format files

Source: Internet
Author: User

As an extension, you need to understand the usage of DotNetZip. See:
C #. NET uses a third-party class library DotNetZip to decompress/compress the Zip file

You also need to understand the basic method of the embedded resource source file of a single file. For details, refer:
WPF calls embedded non-. net EXE resource files

Author: yijian

If you have a large number of files or want to package them into resource files in any format, you can package them into a ZIP file, embedding it in a resource file is a good choice:

Using System. reflection; // ++ using System. IO; using Ionic. zip; namespace packZip {// <summary> // MainWindow. interaction logic of xaml // </summary> public partial class MainWindow: Window {
List <string> fileList = new List <string> (); public MainWindow () {InitializeComponent (); String projectName = Assembly. getExecutingAssembly (). getName (). name. toString (); using (var stream = Assembly. getExecutingAssembly (). getManifestResourceStream (projectName + ".f.zip") {Byte [] B = new Byte [stream. length]; stream. read (B, 0, B. length); MemoryStream m = new MemoryStream (B); using (ZipFile zip = ZipFile. read (m) {zip. extractAll (System. IO. path. getTempPath (), ExtractExistingFileAction. overwriteSilently );
Foreach (ZipEntry entry in zip)
{
FileList. Add (entry. FileName );
}}} Private void Window_Closing (object sender, System. ComponentModel. CancelEventArgs e) {string s = System. IO. Path. GetTempPath ();
Foreach (string f in fileList)
{
If (File. Exists (s + f ))
File. Delete (s + f );
}}}}

In this example, the file traversal and cleanup in the ZIP file are added at the end of the program, so that no trace is left after use, and the job will be brilliant.

Related Article

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.