0

I try to create an .Zip File with C# without using the Tempfolder or change the Temp folder before create.

Normally I would build this scenario in Powershell but this time we need an C# code, cuz the old Windows machines wont have Powershell greater then v1...

Attached my code... Im very sure there are many improvements to make but it would be enough if I could create an .Zip without Temp or chaging Temp before.

        // Umgebungsvariable abfragen
        value = Environment.GetEnvironmentVariable("TEMP");
        value1 = Environment.GetEnvironmentVariable("TMP");

        if (value == "D:\\ZipTemp" & value1 == "D:\\ZipTemp")
        {
            value = Environment.GetEnvironmentVariable("TEMP");
            Console.WriteLine("Die Umgebungsvariable zeigt schon auf den richtigen Pfad");
            Console.WriteLine("Die Umgebungsvariable heißt {0}", value);
            ZipFile.CreateFromDirectory(startPath, zipPath);
            Console.ReadLine();
        }
        else
        {
            Environment.SetEnvironmentVariable("TEMP", "D:\\ZipTemp");
            Environment.SetEnvironmentVariable("TMP", "D:\\ZipTEMP");
            value = Environment.GetEnvironmentVariable("TEMP");
            _ = Environment.GetEnvironmentVariable("TMP");
            Console.WriteLine("Die Umgebungsvariable heißt {0}", value);
            Console.WriteLine("Die Umgebungsvariable heißt {0}", value);
            ZipFile.CreateFromDirectory(startPath, zipPath);
            Console.ReadLine();
        }
Rewler
  • 1
  • 1
  • 1
    Does this answer your question? [Creating a ZIP Archive in Memory Using System.IO.Compression](https://stackoverflow.com/questions/17232414/creating-a-zip-archive-in-memory-using-system-io-compression) – Drag and Drop Oct 02 '20 at 12:10
  • "I try to create an .Zip File with C# without using the Tempfolder or change the Temp folder before create." **Why?** – Ian Kemp Oct 02 '20 at 12:25
  • @IanKemp we are using FBWF and temp isnt excluded. So we got problems while creating .Zip files that the FBWF throws an error and the .zip file cannot be created – Rewler Oct 02 '20 at 12:36
  • @DragandDrop no sorry this is not the right way to solve this problem. Thx – Rewler Oct 02 '20 at 12:40
  • If you got an exception, you'd better put it including the stack in your question. – shingo Oct 02 '20 at 15:08

0 Answers0