The ProgramData folder may be a better choice for the purpose.
How to correct "Access denied" for a file (.txt or .csv) written & saved (in installation folder) by the software while doing calculation & then use it for further calculation in a software written in Visual Basic?

Hi,
After installing my Astrology program ("Astro Prog") written in VB, whenever I open it I get this "Error" message;
System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\Astro Prog\Detected Moon positions.txt' is denied.
To correct it, I have to go to the "Program Files (x86)" --> Astro Prog --> Right Click it --> Properties --> Security --> Edit --> Select "Users" --> Tick "Full Control".
Is there any way to prevent this "Error" occurring?
I want to know how to give "Full Control" to the "Installation Folder" on programming.
Could you please let me know?
Thanks
VKSB
Developer technologies VB
3 answers
Sort by: Most helpful
-
-
MotoX80 36,291 Reputation points
2023-12-24T16:25:27.99+00:00 Don't put user data in your software install folder.
-
Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
2023-12-26T08:31:34.2933333+00:00 Hi @VKSB ,
If you want to give "Full Control" to the "Installation Folder" on programming, try using DirectorySecurity Class with FileSystemAccessRule Class.
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.