Note that there are some explanatory texts on larger screens.

plurals
  1. POFile system paths and Directory.Exists()
    primarykey
    data
    text
    <p>I'm at a bit of a loss on this one ... can't seem to understand what is going on.</p> <p>I have an app that writes some files to a configured output directory, but before that, when the application loads I do this ...</p> <pre><code>string path = ConfigurationManager.AppSettings["TempDir"]; if (!Directory.Exists(path)) Directory.CreateDirectory(path); </code></pre> <p>My problem is that in my case the path is a network based location "\MyServer\Share" and when i use that path it works, but the path i'm using is actually "Z:\" because the share is mapped and is automatically mapped in all user sessions across the network. </p> <p>I want to use "Z:\" but it doesn't work throwing back an error saying "all or part of the path doesn't exist".</p> <p>I immediately thought "oh this must be permissions" so i checked it against say "G:\" which worked and has the same permissions applied ... </p> <p>For all shares in question my user account has full control permissions on the location.</p> <p>Initially i thought it might be something like this: <a href="https://stackoverflow.com/questions/4254465/directory-exists-not-getting-mapped-directory">Directory.Exists not getting mapped directory</a> But then i remembered that it couldn't be that the app is running under another account because I checked and </p> <ol> <li>its only a console app </li> <li><p>the line before is this:</p> <pre><code>AppDomain.CurrentDomain.SetThreadPrincipal(new WindowsPrincipal(WindowsIdentity.GetCurrent())); </code></pre></li> </ol> <p>.. as i understand the purpose of this is to ensure that the appdomain is running under the context of the current windows user, that includes all "threads created within the app domain" unless otherwise specified </p> <p>Any ideas?</p> <p>EDIT:</p> <p>Looking through process monitor as Richard suggests ( see comments below) shows that if i use the full unc path "\MyServer\Share" the request is made as I would expect, if i use the mapped path "Z:\" it still requests the full unc path "\MyServer\Share" (presumably it is doing some form of translation in the inner workings of .net).</p> <p>so no matter what i'm requesting a full unc path "\MyServer\Share" and yet only by explicitly specifying the full unc path can i access it ... weird !!!</p> <p>The code posted above is exactly as I have written it in my console application, there's no other stuff going on yet other than that principle thing as these are the first lines of code to execute in my console application.</p> <p>Hmmm ...</p> <p>EDIT 2:</p> <p>Ok now i'm really confused, when put a breakpoint on the configuration file request line above and run it up to the breakpoint then clear out process monitor and step over that and the if statement nothing appears in the process monitor as I would expect it to ... </p> <p>Why would that happen?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload