-1

I have a desktop application in which the user is able to specify the input and output directories.Things work fine for local directories;but people have started complaining about network locations accessed using UNC Naming Conventions.

If the user pastes the UNC Path,the code checks if the Directory exists using the following method

if(Directory.Exists(selecteddir)
{
  // all good
}

This method returns false for some network locations situated on other machines.I have tested using default local machine UNC Path \\?\C:\my_dir and the code works fine. The application runs with administrative rights .

Im new to accessing network locations in C# Code.Is there any specific way to do this? If the user has already performed windows based authentication for the UNC Shares,wont these shares be accessible by the c# application?

Please advice on how to go forward.

Update:

I have also tried using directory info

DirectoryInfo info1 = new DirectoryInfo(@textbox.Text);
if (info1.Exists)
 {
 return true;
 }
techno
  • 6,100
  • 16
  • 86
  • 192

1 Answers1

1

I have faced this situation many times. In the end, I believe that there is some issue with Directory.Exist method and I leave it.

Now, I am using DirectoryInfo class to check that like this.

DirectoryInfo info = new DirectoryInfo(@"Your Path");
if (info.Exists)
{

}

It is working fine for now. So there are other reasons too but it works for me. And of course, it does not resolve the impersonation issue.

Keyur Ramoliya
  • 1,900
  • 2
  • 16
  • 17
  • Thanks for your input.What exactly is the impersonation issue? – techno Aug 25 '18 at 05:16
  • In the .NET, "Impersonation" means running your code under a specific user account. – Keyur Ramoliya Aug 25 '18 at 05:19
  • okay.When a user attempts to access a network resource (using explorer),he will be prompted for the password right? If the person gets access to the resource by supplying the password,will that resource remain accessible to my c# application until he logs off ? – techno Aug 25 '18 at 05:21
  • I think No because both are the separate thing, means If a person provides credential in UAC in explorer then that credential will not work within your application. – Keyur Ramoliya Aug 25 '18 at 05:26
  • Have you encountered this issue? If yes,how did you manage to sort out this? – techno Aug 25 '18 at 05:27
  • Actually, We are using UNC paths in our on-premises so such paths are accessible in the application as well as windows explorer. Still, we sometimes face this issue in case of network drop. – Keyur Ramoliya Aug 25 '18 at 05:31
  • Good to know that.. Thanks – techno Aug 25 '18 at 05:41
  • The issue still exists when using directoryinfo. – techno Aug 25 '18 at 06:34