Access to the path was denied by doing "File.Writealltext"

Asked

Viewed 740 times

1

Follows code:

public static string pathname = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory.ToString()) + @"\Arquivo_Principal";

if (!File.Exists($@"{pathname}\Musica\{nomemusica}.txt"))
{
    File.WriteAllText($@"{pathname}\Musica\{nomemusica}.txt", letramusica, Encoding.UTF8);
}

Some solution?

  • Are you running VS as an administrator? is Windows Forms? It looks like permission in the folder..

  • 1

    Right, run as admin the application, check write permissions on Windows in that folder, in the security tab.. also check that these paths are correct {pathname}

  • I imagine that in the other notebook there is the right folder? ... \

  • Think the problem happens this when it doesn’t run exe like Adm

  • So there is no need to run as Adm, however you will have to grant permission in the folder, it goes in Explorer, property in the folder and security tab.. and grant permissions there.. especially if the application is ex on the Desktop.. then the security level is higher, and so on..

  • Each time user install .exe, will get very boring to go there on permission > property > security. There is no way to take that permission ? Just install and run

  • 1

    https://stackoverflow.com/questions/7288444/how-to-give-read-write-permissions-to-a-folder-during-installation-using-net

  • Face, Micrososft’s Windows Installer gives a lot of headache. I decided to use Inno Setup. It already solves everything and for free.

  • I give up!!! Doubt anyone solve this problem.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.