2

I have this code for creating a path for a database:

static string folder = Application.UserAppDataPath; 
static string fisier = "prog.db"; 
string file = folder + "\\" + fisier;

And this code for delete the database:

if (System.IO.File.Exists(file))
   System.IO.File.Delete(file);

And this code for wirting the database:

if (!System.IO.File.Exists(file)) 
            {
                System.IO.File.WriteAllText(file, "");
            }

The codes work perfectly, but the problem is with the privileges. To some people, is a problem with the deleting of database, the application will crash becouse will can not delete the database. Not works only for some people, in my case, work perfectly, but I want to resolve the problem to not crash if you don't have the privileges.

AnDr3yy
  • 239
  • 2
  • 5
  • 16
  • Minor point: Use `Path.Combine` to create the path, not string concatenation. – Mark Byers Nov 07 '12 at 15:09
  • For me works, and for other people, but for two friends of mine don't work becouse they don't have the privileges. Why for me work, and for they, don't ? – AnDr3yy Nov 07 '12 at 15:11
  • You need to check the Active Directory Groups that you are all assigned too and permissions for the folder in which it resides. – Derek Nov 07 '12 at 15:13
  • And how I can to this automatically ? The app do the work. – AnDr3yy Nov 07 '12 at 15:16
  • You need to investiage that manually. to see why you have permissions above other users – Derek Nov 07 '12 at 15:18
  • What kind of exception are you getting? I tried running this as both admin and non admin account and this works. Is this being run on a personal computer or a domain environment that might have more restrictions? – Mataniko Nov 07 '12 at 15:22

1 Answers1

0

Error handling: try-catch is your friend.

Bradley Thomas
  • 4,060
  • 6
  • 33
  • 55