I assume your code is running on a Windows7 or newer box.
As Sorceri hints in his comment, your app might be running under standard rights, and you used elevated rights to map the drive.
If this is the case, you have 2 solutions:
Either set the program to run with higher privileges
Check the share and file security on the share you are mapping.
Hopes this helps.