Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I created a Windows executable by developing a very simple .NET console application in Visual Studio. The executable opens up a mapped drive and reads the files from that mapped drive. The mapped drive points to a UNC path (ie: \\uncpath\uncpath\etc...). I know my user has permissions to that mapped drive because I created it. When I run the *.exe file, I get this exception, which from what I've read, is the result of permissions issues. How can I allow read access to that mapped drive from the program? Note, this exe runs fine in Windows XP. The problem results after deploying to Windows Server 2008. I have not tried Windows 7, but I will do that next.

As a side note, I'm also wanting to schedule this via Windows Task Scheduler, but I believe there's a way to set a Windows user on the task during task creation. I'm not using the Windows Task Scheduler thought yet. The exception below happens when running manually when logged into Windows Server 2008 when using my Windows account.


   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler)
   at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
   at System.IO.Directory.GetFiles(String path)
   at LdwMonitor.Program.ScanLdwLogs() in C:\Source\HimcMonitor\LdwMonitor\Program.cs:line 83
   at LdwMonitor.Program.Main(String[] args) in C:\Source\HimcMonitor\LdwMonitor\Program.cs:line 17

Source code throwing the exception:

    string[] fileEntries = Directory.GetFiles(rootDir);
share|improve this question
Why does it need a drive letter? –  Greg Askew Sep 17 '12 at 22:40
Because the .NET System.IO library can only read and work with Windows drive letters. –  MacGyver Sep 17 '12 at 22:46
Not sure what that would be based on. I've used Directory.GetFiles with UNC paths. –  Greg Askew Sep 17 '12 at 22:48
Clarification--I read that on a Stack Overflow answer about UNC paths, but now I'm reading that System.IO.Path can interpret UNC paths. msdn.microsoft.com/en-us/library/system.io.path(v=vs.100).aspx ... can't trust everything you read on the internet. Let me play with the code and use the UNC path instead, and I'll let you know –  MacGyver Sep 17 '12 at 22:50
Does the server see the network share as being within its Intranet zone? I believe that you may run into .NET security issues if the server thinks that the fileshare is in its Internet zone. –  Chris McKeown Sep 17 '12 at 22:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.