UnauthorizedAccessException when reading files... BUT....

  • Thread starter Thread starter Sonnich Jensen
  • Start date Start date
S

Sonnich Jensen

Hi

I have made this programme, which behaves in some funny ways

The line is question is:

string[] lines = System.IO.File.ReadAllLines(FFilename + ".db3");

When the exe incl data files are copied to a new computer - it will cause a System.UnauthorizedAccessException error when accessign the file.
There is a try-catch which does not catch it.

If I run is "As admin" it will work
After that I can run it normally after that it will work as nothing has ever been wrong.

When running it from the IDE and debugging it it will work as there is not problem.

So only when copied and run _until_ once as admin it will fail

I can add:
File.SetAttributes(FFilename + ".db3", FileAttributes.Normal);

but will that be a sure way for the future (I am out of computers to test on)
 
Back
Top