0

So i am writing a program in C#, I need to add files from within my project to a folder on the users system.

I have a folder within my 'Solution Explorer' in visual studio 2013, I wish for these files to be somehow extracted to a directory on the users System.

For example:

  1. Application is executed.
  2. Application extracts files from within itself to %appdata%/MyFiles/files

I am new with C# and learning so please let me know whether this is possible or not and if there is a better way to go about this.

Thanks in advance.

1

1 Answer 1

0

Use a new class in .Net 4.5 called ZipFile

You can extract files.

using System;
    using System.IO;
    using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

I could be wring, but does this just extract files from .zip archives?
showed you an example that will create with the help of CreateFromDirectory and with the help of ExtractToDirectory it will extract. So what you need is to call ExtractToDirectory and give it a right path that yo ucan change in the zipPath variable.
So will the above method extract files from within the executable itself?
Please give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.