Add the ZIP file to the program funding source file and decompress the file at run time.

Source: Internet
Author: User

Add the ZIP file to the program funding source file and decompress the file at run time.

Today, I am doing research on the installation package program. My colleagues previously published a lot of scattered files into an installation folder for users. This is a poor experience. I hope to package all the files into one..

Solution Process:

1. Use the WinRAR tool to package all scattered files into a ZIP file, such as SetupRes.zip.

2. Create a console or WinForms program project as a "package project ";

3. Place the setupres.zip file under the root directory of the package project, and select this file. properties-embedded resources;

4. Add the following code:

Class Program {static void Main (string [] args) {// extract the sample string currNamespace = "leleapp1"; string fileName = "SetupRes.zip"; string resourceName = string. format ("{0 }. {1} ", currNamespace, fileName); Stream so = Assembly. getEntryAssembly (). getManifestResourceStream (resourceName); if (so! = Null) {WriteStreamFile (fileName, so); System. IO. Compression. ZipFile. ExtractToDirectory (fileName, ". \"); Console. WriteLine ("file decompressed successfully! ");} Console. read ();} private static void WriteStreamFile (string fileName, Stream stream) {FileStream fs = File. openWrite (fileName); int bytesRead = 0; byte [] buffer = new byte [65536]; while (bytesRead = stream. read (buffer, 0, buffer. length)> 0) {fs. write (buffer, 0, bytesRead);} stream. close (); fs. close ();}}

5. Compile, run, and find that the running directory has been extracted from the ZIP file and the decompressed directory.

In the future, it will be convenient to install the. NET program!

 

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.