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