C #, working with files, "Unauthorized access"?

I learn about opening and saving files from C #, and it seems that Vista will not allow my program to save the file in the root of C: \ unless I started it in administrator mode.

Any ideas on how to let my program play with any files she wants?

Thank!

private string name;

private void open_Click(object sender, EventArgs e)
{
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        name = openFileDialog1.FileName;
        textBox1.Clear();
        textBox1.Text = File.ReadAllText(name);
        textBox2.Text = name;
    }
}

private void save_Click(object sender, EventArgs e)
{
    File.WriteAllText(name, textBox1.Text);
}
+3
source share
3 answers

, . , → → . "requestExecutionLevel" "requireAdministrator". , "" .

+5

.

, .

, , runas .

, .

+4

UnauthorizedAccess. :

  • path , .

  • .

  • .

: -)

0

Source: https://habr.com/ru/post/1782083/


All Articles