Good day. I need advice, because I do not understand which way to dig to solve the problem.
There is a network folder in which text documents lie that need to be read. The view code Directory.Exists ([folder path]) gives an error about the existence of the folder until I manually open the specified path in Explorer. Or any other folder on the server. After opening the folder, the algorithm works like a clock.
What exactly happens when you manually open the folder at the system level, which ensures the future correct operation of the program? And whether there are assumptions how it is possible to provide this behavior program?
The code below uses the one found here ( https://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share/39540451#39540451 ) to provide forced user login What happened to him, that without him, when accessing the path above - the folder does not exist until it is opened in the explorer.
List<string> _directories = new List<string> { @"\\[server01]\WorkflowTemplate\", @"\\[server02]\WorkflowTemplate\", @"\\[server03]\WorkflowTemplate\" }; ImpersonationHelper.Impersonate(domain, login, pwd, delegate { foreach (string dir in _directories) { if (!Directory.Exists(dir)) { Console.WriteLine("Directory {0} doesn't exists.", dir); } else { Console.WriteLine("{0} has {1} sudfolder", dir, Directory.GetDirectories(dir).Count()); } } });