3

i have an issue where i cannot access to any file in a mapped folder

my drive N: is mapped to \erpu9\clients\, and i have 1.txt file that i'm try to read.

the function File.Exists(@"N:\1.txt") retun false, but File.Exists(@"\\erpu9\clients\1.txt") return true. same thing happened in FileInfo.Exists.

when i try to run File.ReadAllLines(@"N:\1.txt") i got exception: Could not find a part of the path 'n:\1.txt', but File.ReadAllLines(@"\\erpu9\clients\1.txt") is working fine

I'm really lost here, Any suggestions?

i'm using Windows 10, VS2013 if it relevant

Moshe Stone
  • 125
  • 2
  • 8
  • 3
    Is the drive mapping on the same computer and for the same user that your program is running on/under? – nvoigt Mar 08 '17 at 08:51
  • 1
    When you browse N: in the file explorer, can you see the file ? Can you open 1.txt in a text editor, without any permission issues ? Are you properly escaping the backslashess, `File.Exists("N:\1.txt")` should be `File.Exists("N:\\1.txt")` or `File.Exists(@"N:\1.txt")` etc. – nos Mar 08 '17 at 08:51
  • 2
    If you map the file when you have elevated privileges you won't see the mapping when you don't have elevated privileges, and vice-versa. Perhaps that's what's happening. – Matthew Watson Mar 08 '17 at 08:58
  • yes, i can see the file in FileExplorer, and edit it and delete. cannot find any reasonable reasons for this – Moshe Stone Mar 08 '17 at 09:06
  • 1
    Are you runnning your app as administrator? If yes, try not to run it as administrator – ehh Mar 08 '17 at 10:20
  • 1
    Drive mappings are per user. You either run this app as an administrator, or in IIS or another Windows Service - anyway, not under your current user account. – CodeCaster Mar 08 '17 at 12:11

1 Answers1

6

If you run Visual studio with admin privilege, it's mean the user that run application in debug is different from the user that map \\erpu9\clients to N:.

Try to start visual studio with you current user and not with admin.

Ygalbel
  • 5,214
  • 1
  • 24
  • 32