Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.UnauthorizedAccessException: Access to the path "..." is denied

Tags:

c#

wpf

clickonce

I have C# wpf installation done with .net using click once installation. All works fine. Then I have the following code which is part of the installed program:

String destinationPath = System.Windows.Forms.Application.StartupPath + "\\" + fileName;
File.Copy(path, destinationPath, true);
this.DialogResult = true;
this.Close();

But I get this error:

System.UnauthorizedAccessException: Access to the path C:\user\pc\appdata\local\apps\2.0....... is denied.

at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost) at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)

Is it a permission error or do I need to tweak something in my code?

What puzzles me is why the user is able to install the program using click once into that directory without any issues, but uploading a file to it doesn't work?

like image 241
user5313398 Avatar asked Sep 16 '16 15:09

user5313398


People also ask

What is System UnauthorizedAccessException?

An UnauthorizedAccessException exception is thrown when the operating system denies access because of an I/O error or a security error. If you are attempting to access a file or registry key, make sure it is not read-only.

Why is access to the path denied?

You may see “Access to the path is denied” error if the application is not able access to a path that is trying to read or write. This will show up as 401 Unauthorized error in IIS logs.

How do I fix access denied in Visual Studio?

0x80070005 - Access Denied To work around this issue, coordinate with your system administrator or other IT professional to make sure that these processes don't lock Visual Studio files. The user who is trying to install Visual Studio doesn't have administrator credentials on the computer.


1 Answers

I was running a program that would generate file. The destination folder was read only. And it would crash with the error. Removing the read-only attribute using folder properties resolved the error.

like image 84
Ziaullah Khan Avatar answered Oct 13 '22 00:10

Ziaullah Khan