i am doing a project that unzips a .zip file to the path "C:\Program Files (x86)". It returns the error :
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in Ionic.Zip.dll
I search a lot but i can´t understand a way to resolve this problem. Help me please .
My code :
namespace UTAD__VPN_w7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buscarpasta()
{
DialogResult result = this.folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
/*string pedro = folderBrowserDialog1.SelectedPath;
string pedro2 = pedro.Replace("\\", "\\\\");
textBox1.Text = pedro2;*/
string pasta1 = folderBrowserDialog1.SelectedPath;
var pasta2 = pasta1.Replace(@"\", @"\\");
textBox1.Text = pasta2;
}
}
private void MyExtract()
{
string zipToUnpack = "C:\\Users\\Zé Eduardo\\Music\\Cisco.zip";
string unpackDirectory = textBox1.Text;
using (ZipFile zip1 = ZipFile.Read(zipToUnpack))
{
// here, we extract every entry, but we could extract conditionally
// based on entry name, size, date, checkbox status, etc.
foreach (ZipEntry e in zip1)
{
e.Extract(unpackDirectory, ExtractExistingFileAction.OverwriteSilently);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
buscarpasta();
}
}
I get the path with the folderbrowserdialog1 and then i unzip clicking the button 1
C:\Program Files
has been restricted for non-administrators. Search for[windows] UAC
and[windows] privileges
here (or on Google without the[]
characters, and you'll find thousands of results that explain exactly what the problem is and what needs to be done to work properly with UAC and privileges.